Skip to content

Ari - Octos - JS-Scrabble#24

Open
arrriiii wants to merge 6 commits into
Ada-C9:masterfrom
arrriiii:master
Open

Ari - Octos - JS-Scrabble#24
arrriiii wants to merge 6 commits into
Ada-C9:masterfrom
arrriiii:master

Conversation

@arrriiii

@arrriiii arrriiii commented May 18, 2018

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? storing information in local variables and looping through arrays are all very similar to Ruby.
What was a challenge you faced in this assignment? Overall javascript syntax and the logic for highestScoreForm function were the most challenging pieces of this project-- but once I applied the same patterns from our Ruby scrabble project, it became much easier to implement.
Do you have any recommendations on how we could improve this project for the next cohort? Straightforward project. Curious if we could have use this syntax sooner-- < Scrabble.Player = class { >. It was difficult to google examples.

@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 a few comments inline for you to review, but in general this is a solid submission.

Comment thread scrabble.js
for( let letter of wordArray ) {
switch (true) {
case /[aeioulnrst]/i.test(letter):
sum += 1;

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. When the data is intertwined with the code that uses it, 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
tieBreaker(first, second) {
if (first.length == 7) {
return first;
} else if (second.length == 7) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of a helper method to clarify this logic.

Comment thread scrabble.js
} else if (length > 7) {
throw 'Word length must be less than 7';
} else if (length === 0) {
throw 'Word cannot be empty';

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}`);
}

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