Skip to content

Anne Watson -- Octos -- JS-Scrabble#19

Open
annehwatson wants to merge 13 commits into
Ada-C9:masterfrom
annehwatson:master
Open

Anne Watson -- Octos -- JS-Scrabble#19
annehwatson wants to merge 13 commits into
Ada-C9:masterfrom
annehwatson:master

Conversation

@annehwatson

Copy link
Copy Markdown

JS Scrabble

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
What patterns were you able to use from your Ruby knowledge to apply to JavaScript? Loops and conditionals. Using jest asserts was similar to minitest.
What was a challenge you faced in this assignment? I'm not sure on the semicolon placement or if they are all there.
Do you have any recommendations on how we could improve this project for the next cohort?

@droberts-sea

Copy link
Copy Markdown

JS Scrabble

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene yes
Comprehension questions yes
General
score calculates score, has appropriate params and return value yes
highestScoreFrom calculates highest scoring word, has appropriate params and return value yes
Player object
Has name and plays properties yes
Has play, totalScore, hasWon functions yes
Has highestScoringWord and highestWordScore functions yes
Overall Good work overall! I've left some comments inline that you should review, but in general this is a solid submission.

Comment thread scrabble.js
switch (letter) {
case 'a':
case 'e':
case 'i':

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not a big fan of organizing the letter scores in a switch statement like this. It's not very DRY (you've had to type case 26 times), but more importantly the data is intertwined with the code that uses it, which means there's no easy way to reuse this information.

For example, what if the player had a hand full of tiles, and you wanted to be able to display the value of each of those letters? You would have to copy/paste this switch in that code, or at least extract it to a method.

A better approach would be to store the scores in a hash:

const LETTER_VALUES = {
  a: 1,
  b: 3,
  // ...
}

then here you could use it like this:

word.forEach((letter) => {
  const value = LETTER_VALUES[letter.toLowerCase()];
  if (value) {
    totalScore += letter.toLowerCase();
  } else {
    throw new Error(`Invalid character ${letter}`);
  }
}

Comment thread scrabble.js
if (word.length > 7) {
throw 'Words must be 7 letters or less';
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Instead of throwing a string, you should throw an instance of Error. That gives you access to stack trace information. Something like this:

if (condition) {
  throw new Error(`Invalid word ${word}`);
}

Comment thread specs/scrabble.spec.js
test('returns false when score < 100', () => {
const player = new Scrabble.Player('test player');
const words = [{word: 'academy', score: 65}, {word: 'cat', score: 5}, {word: 'goat', score: 5}];
let totalScore = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like how explicit and intentional you are here about what the word scores should be. That makes these tests very readable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants