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

Ampers - Maddie Shields #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
70 changes: 68 additions & 2 deletions scrabble.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,82 @@
const 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
};

const Scrabble = {
score(word) {
this.word = word;
// Need to test for invalid 'word'
// if (!/^[a-zA-Z]+$/.test(word)) {
if (!word.match(/^[a-zA-z]+$/)) {

Choose a reason for hiding this comment

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

look at the A-z, it should be A-Z

throw 'Input is not a word';
}




},
highestScoreFrom(arrayOfWords) {

// Need to check input to be consistent to uppercase
// Then need to increment through each letter to tally score.
// if statement for when word is 7 characters exact long
// else statement for >7 that word cannot be that long

let uppercaseWord = word.toUpperCase();
let wordArray = uppercaseWord.split("");
let score = 0

for (let i = 0; i < uppercaseWord.length; i++) {
if (SCORECHART.hasOwnProperty(wordArray[i])) {
score += SCORECHART[wordArray[i]];
}
}

if (wordArray.length ===7) {
score += 50;
}
return score
},

// highestScoreFrom(arrayOfWords) {
// if (this.word) {
// return true;
// }
//
// },
};

Scrabble.Player = class {
constructor(name) {
this.name = name;
}

};

console.log(Scrabble.highestWordFrom);


module.exports = Scrabble;
4 changes: 2 additions & 2 deletions specs/scrabble.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ describe('score', () => {
expect(Scrabble.score('pig')).toBe(6);
});

test.skip('adds 50 points for a 7-letter word', () => {
test('adds 50 points for a 7-letter word', () => {
expect(Scrabble.score('academy')).toBe(65);
});

test.skip('throws on bad characters', () => {
test('throws on bad characters', () => {
expect(() => {
Scrabble.score('char^');
}).toThrow();
Expand Down