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

Pipes - Kee - Scrabble #47

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Added Player class methods
anemonekey committed Nov 20, 2017
commit dc50bd6d2f7d7d6bc3399aca567dc253b8477253
30 changes: 26 additions & 4 deletions scrabble.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Scrabble = {
score: function(word) {
// TODO: implement score
const scores = {
A:1, B:3, C:3, D:2, E:1, F:4, G:2, H:4, I:1, J:8, K:5, L:1, M:3, N:1, O:1, P:3, Q:10, R:1, S:1, T:1, U:1, V:4, W:4, X:8, Y:4, Z:10
};
@@ -27,7 +26,6 @@ const Scrabble = {
}
},

// TODO: add the highestScoreFrom method
highestScoreFrom: function(words) {
if (words.constructor === Array && words.length > 0) {
let highest_score = 0;
@@ -65,9 +63,33 @@ const Scrabble = {
Scrabble.Player = class {
// TODO: implement the Player class
constructor(name) {
this.name = name;
const plays = [];
if (name) {
this.name = name;
this.plays = [];
this._totalScore = 0;
} else {
throw 'No name!';
}
}
play(word) {
if (this.hasWon() === true) { return false; }
if (word) {
let score = Scrabble.score(word);
this._totalScore += score;
this.plays.push(word);
return true;
} else {
throw 'Not a real word!';
}
}

totalScore() { return this._totalScore; }

hasWon() { return this._totalScore >= 100; }

highestScoringWord(){ return Scrabble.highestScoreFrom(this.plays); }

highestWordScore(){ return Scrabble.score(this.highestScoringWord()); }
};

module.exports = Scrabble;