forked from AdaGold/js-scrabble
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Olivia's JS-Scrabble #17
Open
secretsharer
wants to merge
7
commits into
Ada-C7:master
Choose a base branch
from
secretsharer:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cbc16c5
change up, no longer using prototype here after conversation with chr…
secretsharer 56f863d
Kari clears up the confusion about prototype use and constructor use.…
secretsharer 0bf272f
beginning the player constructor function as well as the player proto…
secretsharer c0a8086
Player methods
secretsharer fafbe6d
got rid of some pasta
secretsharer e3f6237
missing brackets
secretsharer ae1deab
tiny typo fixes
secretsharer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,118 @@ | ||
var Scrabble = function() {}; | ||
|
||
// YOUR CODE HERE | ||
Scrabble.prototype.helloWorld = function() { | ||
return 'hello world!'; | ||
var pointValue = { | ||
'a': 1, | ||
'e': 1, | ||
'i': 1, | ||
'o': 1, | ||
'u': 1, | ||
'l': 1, | ||
'n': 1, | ||
'r': 1, | ||
's': 1, | ||
't': 1, | ||
'd': 2, | ||
'g': 2, | ||
'b': 3, | ||
'c': 3, | ||
'm': 3, | ||
'p': 3, | ||
'f': 4, | ||
'h': 4, | ||
'v': 4, | ||
'w': 4, | ||
'y': 4, | ||
'k': 5, | ||
'j': 8, | ||
'x': 8, | ||
'q': 10, | ||
'z': 10 | ||
|
||
}; | ||
|
||
//my initializer | ||
//the constructor initializes and instance of of the "class", constructor is called with new ScrabbleGame, but without 'instance vars' | ||
var ScrabbleGame = function() { | ||
}; | ||
// setting up the structure of scoring on any word | ||
ScrabbleGame.prototype.score = function(word) { | ||
var points = 0; | ||
for (var i = 0; i < word.length; i++) { | ||
points += pointValue[word[i]]; | ||
} | ||
if (word.length > 6) | ||
var wordscore = word.score + 50; | ||
}; | ||
return wordscore; | ||
} | ||
|
||
ScrabbleGame.prototype.highestScoreFrom = function(wordsPlayed) { | ||
var highestScoringWord = "" | ||
var highestWordScore = 0 | ||
for (var i = 0; i < wordsPlayed.length; i++) { | ||
if(score(wordsPlayed[i]) > highestWordScore) { | ||
highestWordScore = score(wordsPlayed[i]) | ||
highestScoringWord = wordsPlayed[i] | ||
} | ||
} | ||
return highestScoringWord | ||
} | ||
|
||
var playscrabble = new ScrabbleGame(); | ||
playscrabble.score(word) | ||
|
||
// Scrabble.prototype.helloWorld = function() { | ||
// return 'hello world!'; | ||
// }; | ||
|
||
module.exports = Scrabble; | ||
//*****************************//PLAYER//************************** | ||
|
||
var Player = function() {}; | ||
|
||
//the constructor initializes and instance of of the "class", constructor is called with new Player with the addition of 'instance' vars, unlike new scrabbleGame | ||
var Player = function(name) { | ||
this.name = name; | ||
this.plays = [], | ||
this.won = false; | ||
}; | ||
|
||
Player.prototype.play = function(word) { | ||
//should add the input word to the plays array | ||
this.plays.push(word); | ||
}; | ||
|
||
Player.prototype.totalScore = function() { | ||
//should SUM and RETURN the score of the players words | ||
var totalScore = 0; | ||
var playscrabble = new ScrabbleGame(); | ||
//iterate over plays | ||
this.plays.forEach(function(word)) { | ||
this.plays[i] += this.plays[i]; | ||
Math.sum(this.plays[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
} | ||
return totalScore; | ||
}; | ||
} | ||
|
||
Player.prototype.hasWon = function() { | ||
//should check if the player has 100 or more points and returns true or false | ||
if (this.totalScore() >= 100) | ||
this.won = true | ||
else { | ||
return this.won | ||
} | ||
} | ||
|
||
Player.prototype.highestScoringWord = function() { | ||
var playscrabble = new ScrabbleGame(); | ||
return playscrabble.highestScoreFrom(this.plays); | ||
} | ||
|
||
Player.prototype.highestWordScore = function() { | ||
var highestWordScore = 0 | ||
for (var i = 0; i < wordsPlayed.length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can call |
||
if(score(wordsPlayed[i]) > highestWordScore) { | ||
highestWordScore = score(wordsPlayed[i]) | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The end of this function should probably go from:
To: