From aa5c3b156d7a1a2cf31173d628828a015e4a1e90 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 11:06:04 -0800 Subject: [PATCH 01/11] set up files --- package-lock.json | 123 ++++++++++++++++++++++++++++++++++++++++++++++ scrabble.js | 50 ++++++++++++++++++- 2 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..80043d7 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,123 @@ +{ + "name": "js-scrabble", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "add-matchers": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/add-matchers/-/add-matchers-0.5.0.tgz", + "integrity": "sha1-UCGQ5HUM1XIWGDkyaLYaFXNm52U=" + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "brace-expansion": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "eslint-plugin-jasmine": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-jasmine/-/eslint-plugin-jasmine-2.9.1.tgz", + "integrity": "sha1-IuGaWfFvOl9kOgSroEQ40OMEcDA=" + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "jasmine": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-2.8.0.tgz", + "integrity": "sha1-awicChFXax8W3xG4AUbZHU6Lij4=", + "requires": { + "exit": "0.1.2", + "glob": "7.1.2", + "jasmine-core": "2.8.0" + } + }, + "jasmine-core": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-2.8.0.tgz", + "integrity": "sha1-vMl5rh+f0FcB5F5S5l06XWPxok4=" + }, + "jasmine-expect": { + "version": "3.8.1", + "resolved": "https://registry.npmjs.org/jasmine-expect/-/jasmine-expect-3.8.1.tgz", + "integrity": "sha512-klARdR5AVX9nZhHhYDlbDYgxgi6kl9DGS0vguhaioKoSwr8HL1uOQ7FFUBASq/sqBL/s2nkh/1efqZ2ugcknFA==", + "requires": { + "add-matchers": "0.5.0" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "1.1.8" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1.0.2" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + } +} diff --git a/scrabble.js b/scrabble.js index 7a1f161..b679ab0 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,14 +1,62 @@ +'use strict'; +var prompt = require('prompt'); +prompt.start(); +prompt.get('word', Scrabble.score) + + const Scrabble = { + score: function(word) { - // TODO: implement score + let score = 0; + // turn word into an array of characters + // forEach loop + // ruby way: + // score = 0 + // word.chars.each do |char| + // score += LETTER_VALUES[char.downcase] + // end + // score += 50 if word.length == 7 + // return score + } // TODO: add the highestScoreFrom method }; + +// wave 2: Scrabble.Player = class { // TODO: implement the Player class }; module.exports = Scrabble; +// where to store the letter value +const LETTER_VALUES = { + '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 +} From 7b56f8b2f9dde0c93aa8e76932bbfe2c35b1c6e2 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 11:44:59 -0800 Subject: [PATCH 02/11] score method --- package-lock.json | 146 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +- scrabble.js | 96 +++++++++++++++++------------- 3 files changed, 205 insertions(+), 40 deletions(-) diff --git a/package-lock.json b/package-lock.json index 80043d7..b7bb24a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,11 @@ "resolved": "https://registry.npmjs.org/add-matchers/-/add-matchers-0.5.0.tgz", "integrity": "sha1-UCGQ5HUM1XIWGDkyaLYaFXNm52U=" }, + "async": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", + "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -23,11 +28,26 @@ "concat-map": "0.0.1" } }, + "colors": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz", + "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, + "cycle": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz", + "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI=" + }, + "deep-equal": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.2.2.tgz", + "integrity": "sha1-hLdFiW80xoTpjyzg5Cq69Du6AX0=" + }, "eslint-plugin-jasmine": { "version": "2.9.1", "resolved": "https://registry.npmjs.org/eslint-plugin-jasmine/-/eslint-plugin-jasmine-2.9.1.tgz", @@ -38,6 +58,11 @@ "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=" }, + "eyes": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz", + "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A=" + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -56,6 +81,11 @@ "path-is-absolute": "1.0.1" } }, + "i": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/i/-/i-0.3.6.tgz", + "integrity": "sha1-2WyScyB28HJxG2sQ/X1PZa2O4j0=" + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -70,6 +100,11 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" + }, "jasmine": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-2.8.0.tgz", @@ -101,6 +136,29 @@ "brace-expansion": "1.1.8" } }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "requires": { + "minimist": "0.0.8" + } + }, + "mute-stream": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", + "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=" + }, + "ncp": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ncp/-/ncp-1.0.1.tgz", + "integrity": "sha1-0VNn5cuHQyuhF9K/gP30Wuz7QkY=" + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -114,6 +172,94 @@ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, + "pkginfo": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.4.1.tgz", + "integrity": "sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8=" + }, + "prompt": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.0.0.tgz", + "integrity": "sha1-jlcSPDlquYiJf7Mn/Trtw+c15P4=", + "requires": { + "colors": "1.1.2", + "pkginfo": "0.4.1", + "read": "1.0.7", + "revalidator": "0.1.8", + "utile": "0.3.0", + "winston": "2.1.1" + } + }, + "read": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz", + "integrity": "sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ=", + "requires": { + "mute-stream": "0.0.7" + } + }, + "revalidator": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz", + "integrity": "sha1-/s5hv6DBtSoga9axgZgYS91SOjs=" + }, + "rimraf": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "requires": { + "glob": "7.1.2" + } + }, + "stack-trace": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz", + "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=" + }, + "utile": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/utile/-/utile-0.3.0.tgz", + "integrity": "sha1-E1LDQOuCDk2N26A5pPv6oy7U7zo=", + "requires": { + "async": "0.9.2", + "deep-equal": "0.2.2", + "i": "0.3.6", + "mkdirp": "0.5.1", + "ncp": "1.0.1", + "rimraf": "2.6.2" + } + }, + "winston": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/winston/-/winston-2.1.1.tgz", + "integrity": "sha1-PJNJ0ZYgf9G9/51LxD73JRDjoS4=", + "requires": { + "async": "1.0.0", + "colors": "1.0.3", + "cycle": "1.0.3", + "eyes": "0.1.8", + "isstream": "0.1.2", + "pkginfo": "0.3.1", + "stack-trace": "0.0.10" + }, + "dependencies": { + "async": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz", + "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k=" + }, + "colors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", + "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=" + }, + "pkginfo": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.3.1.tgz", + "integrity": "sha1-Wyn2qB9wcXFC4J52W76rl7T4HiE=" + } + } + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 18c9026..9415add 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "dependencies": { "eslint-plugin-jasmine": "^2.9.1", "jasmine": "^2.8.0", - "jasmine-expect": "^3.8.1" + "jasmine-expect": "^3.8.1", + "prompt": "^1.0.0" }, "scripts": { "test": "jasmine" diff --git a/scrabble.js b/scrabble.js index b679ab0..6e64b2c 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,28 +1,74 @@ 'use strict'; var prompt = require('prompt'); -prompt.start(); -prompt.get('word', Scrabble.score) +const LETTER_VALUES = { + 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 +}; const Scrabble = { score: function(word) { + // TODO: check length > 0 and < 7 + word = word.toLowerCase(); let score = 0; // turn word into an array of characters + word = word.split(""); // forEach loop - // ruby way: - // score = 0 - // word.chars.each do |char| - // score += LETTER_VALUES[char.downcase] - // end - // score += 50 if word.length == 7 - // return score + word.forEach(function(char) { + if (!(char in LETTER_VALUES)) { + throw char 'is not a character' + } + score += LETTER_VALUES[char]; + } - } + if (word.length == 7) { + score += 50; + } - // TODO: add the highestScoreFrom method + return score; + ); + + + // my old ruby way: + // score = 0 + // word.chars.each do |char| + // score += LETTER_VALUES[char.downcase] + // end + // score += 50 if word.length == 7 + // return score + +} + +// TODO: add the highestScoreFrom method }; +prompt.start(); +prompt.get('word', Scrabble.score) // wave 2: @@ -32,31 +78,3 @@ Scrabble.Player = class { module.exports = Scrabble; // where to store the letter value -const LETTER_VALUES = { - '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 -} From 9e2266064a80a94d7c4acf3fa0af8ebb17dde623 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 12:32:45 -0800 Subject: [PATCH 03/11] writing score method --- scrabble.js | 52 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/scrabble.js b/scrabble.js index 6e64b2c..3edc3b7 100644 --- a/scrabble.js +++ b/scrabble.js @@ -28,47 +28,41 @@ const LETTER_VALUES = { y: 4, z: 10 }; - - +function UserException(message) { + this.message = message; + this.name = 'UserException'; +} const Scrabble = { - - score: function(word) { + score(error, result) { // TODO: check length > 0 and < 7 - word = word.toLowerCase(); - let score = 0; - // turn word into an array of characters - word = word.split(""); - // forEach loop - word.forEach(function(char) { + let score = 0, word = result.word, letter = word.toLowerCase().split(""); + letter.forEach(function(char) { if (!(char in LETTER_VALUES)) { - throw char 'is not a character' + throw new UserException(`${char} is an invalid character`); } score += LETTER_VALUES[char]; } - - if (word.length == 7) { - score += 50; - } - - return score; ); + if (word.length == 7) { + score += 50; + } + console.log(score); + return score; +}, - - // my old ruby way: - // score = 0 - // word.chars.each do |char| - // score += LETTER_VALUES[char.downcase] - // end - // score += 50 if word.length == 7 - // return score - -} +// my old ruby way: +// score = 0 +// word.chars.each do |char| +// score += LETTER_VALUES[char.downcase] +// end +// score += 50 if word.length == 7 +// return score // TODO: add the highestScoreFrom method - }; + prompt.start(); -prompt.get('word', Scrabble.score) +prompt.get(['word'], Scrabble.score) // wave 2: From 5fc45b12a4b8ea6962137c8f20a1053327fe3cac Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 14:43:13 -0800 Subject: [PATCH 04/11] moving into highestScoreFrom method --- scrabble.js | 57 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/scrabble.js b/scrabble.js index 3edc3b7..e97ec3a 100644 --- a/scrabble.js +++ b/scrabble.js @@ -29,46 +29,55 @@ const LETTER_VALUES = { z: 10 }; function UserException(message) { - this.message = message; - this.name = 'UserException'; + this.message = message; + this.name = 'UserException'; } const Scrabble = { - score(error, result) { - // TODO: check length > 0 and < 7 - let score = 0, word = result.word, letter = word.toLowerCase().split(""); + score: function(word) { + if (word.length > 7 || word.length < 1) { + throw new UserException(`Invalid word, must be at least 1 character and less than 7 characters.`); + } + + let score = 0; + let letter = word.toLowerCase().split(""); letter.forEach(function(char) { if (!(char in LETTER_VALUES)) { throw new UserException(`${char} is an invalid character`); } score += LETTER_VALUES[char]; + }); + if (word.length == 7) { + score += 50; } - ); - if (word.length == 7) { - score += 50; - } - console.log(score); - return score; -}, + return score; + }, -// my old ruby way: -// score = 0 -// word.chars.each do |char| -// score += LETTER_VALUES[char.downcase] -// end -// score += 50 if word.length == 7 -// return score + highestScoreFrom: function(arrayOfWords) { + if (arrayOfWords.length === 0) { + throw new UserException(`Uh-oh! No words!`); + } + if (arrayOfWords.length === 1) { + return arrayOfWords.toString(); + } -// TODO: add the highestScoreFrom method + for (let word of arrayOfWords) { + let scores = this.score(word); + console.log(scores); + // scores.max(); + } + }, }; -prompt.start(); -prompt.get(['word'], Scrabble.score) - -// wave 2: Scrabble.Player = class { // TODO: implement the Player class }; +prompt.start(); +prompt.get(['word'], function(error, result){ + let score = Scrabble.score(result.word); + console.log(score); +}) + module.exports = Scrabble; // where to store the letter value From b4303b584f25132eaa4f5cb01eda45a152f619a9 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 15:18:14 -0800 Subject: [PATCH 05/11] highestScoreFrom passes tests --- scrabble.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/scrabble.js b/scrabble.js index e97ec3a..bb04de1 100644 --- a/scrabble.js +++ b/scrabble.js @@ -28,10 +28,11 @@ const LETTER_VALUES = { y: 4, z: 10 }; -function UserException(message) { +const UserException = function UserException(message) { this.message = message; this.name = 'UserException'; -} +}; + const Scrabble = { score: function(word) { if (word.length > 7 || word.length < 1) { @@ -60,15 +61,28 @@ const Scrabble = { return arrayOfWords.toString(); } + let highestWord = arrayOfWords[0]; + for (let word of arrayOfWords) { - let scores = this.score(word); - console.log(scores); - // scores.max(); + let highScore = Scrabble.score(highestWord); + let newWord = Scrabble.score(word); + + if (highScore < newWord) { + highestWord = word; + } else if (highScore === newWord) { + if (word.length === 7) { + highestWord = word; + } else if (highestWord.length === 7) { + } else if (word.length < highestWord.length) { + highestWord = word; + } + } } + return highestWord; }, }; - +// if ((word.length == 7) && (max_word.length != 7)) || ((word.length < max_word.length) && (max_word.length != 7)) Scrabble.Player = class { // TODO: implement the Player class }; From 81b8349100ed1a2e8ad1e681d9463d93888439b8 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 15:52:45 -0800 Subject: [PATCH 06/11] working on methods for player --- scrabble.js | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/scrabble.js b/scrabble.js index bb04de1..f6627e4 100644 --- a/scrabble.js +++ b/scrabble.js @@ -82,16 +82,51 @@ const Scrabble = { }, }; -// if ((word.length == 7) && (max_word.length != 7)) || ((word.length < max_word.length) && (max_word.length != 7)) + Scrabble.Player = class { - // TODO: implement the Player class + constructor(name) { + if (name.length === 0) { + throw new UserException(`Please enter a name!`); + } + this.name = name; + this.currentScore = 0; + this.plays = []; + + } + + play(word) { + if (this.hasWon()) { + // wont allow to play a word if already won (higher than 100 points) + return false; + } + + let wordLetters = word.split(""); + wordLetters.forEach(function(char) { + if (!(char in LETTER_VALUES)) { + throw new UserException(`Come on, play a word!`); + } + }); + this.plays.push(word); + this.currentScore += Scrabble.score(word); + return true; + } + + hasWon() { + return this.currentScore >= 100; + } + + totalScore() { + return this.currentScore; + } + + }; prompt.start(); prompt.get(['word'], function(error, result){ let score = Scrabble.score(result.word); console.log(score); -}) +}); module.exports = Scrabble; // where to store the letter value From 77f6fe7d7c58ce3082b0273816c222bb1dcc7288 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 16:11:11 -0800 Subject: [PATCH 07/11] tests passing, cleaning up --- scrabble.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scrabble.js b/scrabble.js index f6627e4..6de956c 100644 --- a/scrabble.js +++ b/scrabble.js @@ -93,6 +93,9 @@ Scrabble.Player = class { this.plays = []; } + hasWon() { + return this.currentScore >= 100; + } play(word) { if (this.hasWon()) { @@ -111,14 +114,17 @@ Scrabble.Player = class { return true; } - hasWon() { - return this.currentScore >= 100; - } - totalScore() { return this.currentScore; } + highestScoringWord() { + return Scrabble.highestScoreFrom(this.plays); + } + + highestWordScore() { + return Scrabble.score(this.highestScoringWord()); + } }; From 6f8a5c868ab4c2cd4f4b6ac22597be31ccd4c46f Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 16:21:48 -0800 Subject: [PATCH 08/11] method names --- scrabble.js | 57 ++++++++++++++++------------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/scrabble.js b/scrabble.js index 6de956c..16451a7 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,33 +1,9 @@ -'use strict'; -var prompt = require('prompt'); +// 'use strict'; +// var prompt = require('prompt'); const LETTER_VALUES = { - 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 + 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 }; + const UserException = function UserException(message) { this.message = message; this.name = 'UserException'; @@ -36,10 +12,11 @@ const UserException = function UserException(message) { const Scrabble = { score: function(word) { if (word.length > 7 || word.length < 1) { - throw new UserException(`Invalid word, must be at least 1 character and less than 7 characters.`); + throw new UserException(`Invalid word, must be greater than 1 character and less than 7 characters.`); } let score = 0; + // const checkWordValidity = function() { } let letter = word.toLowerCase().split(""); letter.forEach(function(char) { if (!(char in LETTER_VALUES)) { @@ -89,20 +66,20 @@ Scrabble.Player = class { throw new UserException(`Please enter a name!`); } this.name = name; - this.currentScore = 0; + this.playingScore = 0; this.plays = []; } + hasWon() { - return this.currentScore >= 100; + return this.playingScore >= 100; } play(word) { - if (this.hasWon()) { + if (this.hasWon() === true) { // wont allow to play a word if already won (higher than 100 points) return false; } - let wordLetters = word.split(""); wordLetters.forEach(function(char) { if (!(char in LETTER_VALUES)) { @@ -110,12 +87,12 @@ Scrabble.Player = class { } }); this.plays.push(word); - this.currentScore += Scrabble.score(word); + this.playingScore += Scrabble.score(word); return true; } totalScore() { - return this.currentScore; + return this.playingScore; } highestScoringWord() { @@ -128,11 +105,11 @@ Scrabble.Player = class { }; -prompt.start(); -prompt.get(['word'], function(error, result){ - let score = Scrabble.score(result.word); - console.log(score); -}); +// prompt.start(); +// prompt.get(['word'], function(error, result){ +// let score = Scrabble.score(result.word); +// console.log(score); +// }); module.exports = Scrabble; // where to store the letter value From 89bc2e33374986ae2abb39f467b0c35d61094976 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 16:35:48 -0800 Subject: [PATCH 09/11] moving checking validity outside of object --- scrabble.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scrabble.js b/scrabble.js index 16451a7..cabbf3a 100644 --- a/scrabble.js +++ b/scrabble.js @@ -9,6 +9,12 @@ const UserException = function UserException(message) { this.name = 'UserException'; }; +const checkValidity = function checkValidity(char) { + if (!(char in LETTER_VALUES)) { + throw new UserException(`${char} is an invalid character`); + } +}; + const Scrabble = { score: function(word) { if (word.length > 7 || word.length < 1) { @@ -16,12 +22,9 @@ const Scrabble = { } let score = 0; - // const checkWordValidity = function() { } let letter = word.toLowerCase().split(""); letter.forEach(function(char) { - if (!(char in LETTER_VALUES)) { - throw new UserException(`${char} is an invalid character`); - } + checkValidity(char); score += LETTER_VALUES[char]; }); if (word.length == 7) { @@ -82,9 +85,7 @@ Scrabble.Player = class { } let wordLetters = word.split(""); wordLetters.forEach(function(char) { - if (!(char in LETTER_VALUES)) { - throw new UserException(`Come on, play a word!`); - } + checkValidity(char); }); this.plays.push(word); this.playingScore += Scrabble.score(word); From ca9f267df7ddb1a954fdea7acc526f9c2e006f72 Mon Sep 17 00:00:00 2001 From: Lauren Date: Tue, 14 Nov 2017 16:52:46 -0800 Subject: [PATCH 10/11] refactoring checkvalidity --- scrabble.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scrabble.js b/scrabble.js index cabbf3a..7d91057 100644 --- a/scrabble.js +++ b/scrabble.js @@ -83,8 +83,8 @@ Scrabble.Player = class { // wont allow to play a word if already won (higher than 100 points) return false; } - let wordLetters = word.split(""); - wordLetters.forEach(function(char) { + let letter = word.toLowerCase().split(""); + letter.forEach(function(char) { checkValidity(char); }); this.plays.push(word); From 57d7191de064a32d94044926961ccb74e23ade07 Mon Sep 17 00:00:00 2001 From: Lauren Date: Wed, 15 Nov 2017 08:00:09 -0500 Subject: [PATCH 11/11] pull request questions --- .github/PULL_REQUEST_TEMPLATE | 10 +++++----- scrabble.js | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE index 3e78900..aa3a4bd 100644 --- a/.github/PULL_REQUEST_TEMPLATE +++ b/.github/PULL_REQUEST_TEMPLATE @@ -4,8 +4,8 @@ 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? | | -| What was a challenge you were able to overcome on this assignment? | | -| What is your favorite thing about learning a new programming language? | | -| What is your least favorite thing about learning a new programming language? | | -| Do you have any recommendations on how we could improve this project for the next cohort? | | +| What patterns were you able to use from your Ruby knowledge to apply to JavaScript? | I was able to use similar nested if-loops to check against the tie scenarios. Same logic applied to most everything in this problem, I just needed to switch syntax. It was the same pattern of checking the first word in the array against the next and evaluating it. | +| What was a challenge you were able to overcome on this assignment? | I struggled with understanding when to call 'this' and when to call the object 'Scrabble'. I also wanted to DRY up my checkValidity function that I call twice and I overcame that tricky spot but pulling out completely and making it more of a 'globally scoped' function. | +| What is your favorite thing about learning a new programming language? | I am loving that the translation portion of it and it has been fun to revel in the differences. It's neat that JS doesn't have the same functionality as ruby and now we are in the exploration phase of what those differences and similarities are. It's proving to be pretty fun and fascinating! | +| What is your least favorite thing about learning a new programming language? | Syntax confusion. Not quite knowing how to search for what I am needing on the internet. But I'm sure this is normal and is just my own growing-pains that will get better with time and effort. | +| Do you have any recommendations on how we could improve this project for the next cohort? | I wonder if we could have used two classes as opposed to an object and class within that object. Just because it was what we had been working on in class on Tuesday it would have been fun to apply that new knowledge! | diff --git a/scrabble.js b/scrabble.js index 7d91057..22ec49a 100644 --- a/scrabble.js +++ b/scrabble.js @@ -62,7 +62,6 @@ const Scrabble = { }, }; - Scrabble.Player = class { constructor(name) { if (name.length === 0) {