Skip to content
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

Mary Morrison #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 100 additions & 4 deletions scrabble.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,104 @@
var Scrabble = function() {};
var Scrabble = {
scoreChart: {
"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
},

score: function(word) {
var string = word.toUpperCase(),
score = 0;
for(var i=0; i < string.length; i) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will work without i++

score = Scrabble.scoreChart[string[i]];
}
if (string.length === 7) {
score = 50;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this logic should be +50, as opposed to =50

}
return score;
},


highestScoreFrom: function(arrayOfWords) {
var winner = "";
var winningScore = 0;
arrayOfWords.forEach(function(word){
var wordScore = Scrabble.score(word);
if (wordScore > winningScore) {
winner = word;
winningScore = wordScore;
} else if (wordScore === winningScore) {
if (winner.length !== 7) {
if (word.length == 7) {
winner = word;
winningScore = wordScore;
} else if (word.length < winner.length) {
winner = word;
winningScore = wordScore;
}
}
}
});
return winner;
}


// YOUR CODE HERE
Scrabble.prototype.helloWorld = function() {
return 'hello world!';
};

var Player = function(name) {
this.name = name;
this.plays = [];
};


Player.prototype.totalScore = function() {
var playersWords = this.plays;
var totalScore = 0;

for (var i = 0; i < playersWords.length; i) {
var wordScore = Scrabble.score(playersWords[i]);
totalScore = wordScore;
}
return totalScore;
};

Player.prototype.hasWon = function(player) {
var score = this.totalScore(player);

if (score > 100) {
return true;
} else {
return false;
}
};
module.exports = Scrabble;


// scoreWord = Scrabble.score("yolo");
// console.log(scoreWord);
//
//
// declareWinner = Scrabble.highestScoreFrom(["yolo", "poodle", "cheese", "zzzzzz", "aaaaaaa"]);
// console.log(declareWinner);