From b64cb9f7793c011ff2732527a56b70e68ee93d3b Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Tue, 15 Nov 2016 15:06:56 -0800 Subject: [PATCH 1/9] can get word scores and word with highest score --- scrabble.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/scrabble.js b/scrabble.js index a7d0745..9613041 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,8 +1,108 @@ var Scrabble = function() {}; // YOUR CODE HERE -Scrabble.prototype.helloWorld = function() { - return 'hello world!'; -}; + +var Tiles = { + 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 +} + +var pointArray = [5, 10, 13] + +var wordArray = ["GATO", "RABBIT", "VACUUM"] +// console.log(Tiles.A) + +// score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. +// highestScoreFrom(arrayOfWords): returns the word in the array with the highest score. +// Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters. +// Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles. +// If the there are multiple words that are the same score and same length, pick the first one in supplied list. + + +var assign = function(letter) { + return Number(Tiles[letter]) +} +// undefined +// > assign('A') +// 1 +// undefined +// > Tiles['Z'] = 10 +// 10 +// > Tiles +// { A: 1, E: 1, I: 1, O: 1, Z: 10 } +// > assign['Z'] +// undefined + +var score = function(word) { + var wordScore = 0 + var ltr_array = word.split(''); + ltr_array.forEach(function(element) { + var point = assign(element); + wordScore += point; + }); + // console.log(wordScore); + return wordScore + } + + +score('GATO') +console.log( '**** 5 ****' ) + + +var scores = function( array ) { + array.forEach(function(element) { + console.log(score(element)); + }); +} + + + + +scores(wordArray) +console.log( '*****' + pointArray + '*****') +// Scrabble.prototype.helloWorld = function() { +// return 'hello world!'; +// }; + +var highestScore = function( array ) { + var maxScore = 0 + var word = '' + array.forEach(function(element) { + var points = score(element); + if( points > maxScore ) { + word = element; + maxScore = points + } + } + ); + console.log(word); +} + +highestScore(wordArray) +console.log( '***VACUUM***') module.exports = Scrabble; From 8d7006d7b4eac9d8f9719b97ab8beb467a6221cf Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Tue, 15 Nov 2016 15:26:03 -0800 Subject: [PATCH 2/9] added highestScoreShortestWord method --- scrabble.js | 66 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/scrabble.js b/scrabble.js index 9613041..329610e 100644 --- a/scrabble.js +++ b/scrabble.js @@ -31,9 +31,14 @@ var Tiles = { Z: 10 } -var pointArray = [5, 10, 13] +var wordPointArray = [5, 10, 13] var wordArray = ["GATO", "RABBIT", "VACUUM"] + +var shortWordArray = ["AEI", "MAP", "ZAP" ] + +var shortWordPointArray = [3, 7, 14] + // console.log(Tiles.A) // score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. @@ -46,16 +51,8 @@ var wordArray = ["GATO", "RABBIT", "VACUUM"] var assign = function(letter) { return Number(Tiles[letter]) } -// undefined -// > assign('A') -// 1 -// undefined -// > Tiles['Z'] = 10 -// 10 -// > Tiles -// { A: 1, E: 1, I: 1, O: 1, Z: 10 } -// > assign['Z'] -// undefined + +// ******************************** var score = function(word) { var wordScore = 0 @@ -68,26 +65,25 @@ var score = function(word) { return wordScore } - -score('GATO') +console.log(score('GATO')) console.log( '**** 5 ****' ) +// ******************************** -var scores = function( array ) { +var showScores = function( array ) { array.forEach(function(element) { console.log(score(element)); }); } - - -scores(wordArray) -console.log( '*****' + pointArray + '*****') +showScores(wordArray) +console.log( '*****' + wordPointArray + '*****') // Scrabble.prototype.helloWorld = function() { // return 'hello world!'; // }; +// ******************************** var highestScore = function( array ) { var maxScore = 0 var word = '' @@ -95,14 +91,42 @@ var highestScore = function( array ) { var points = score(element); if( points > maxScore ) { word = element; - maxScore = points + maxScore = points; } } ); - console.log(word); + return word; } -highestScore(wordArray) +console.log(highestScore(wordArray)) console.log( '***VACUUM***') +// ******************************** + +var highestScoreShortestWord = function( array ) { + var maxScore = 0 + var word = '' + array.forEach(function(element) { + var points = score(element); + if( points > maxScore) { + word = element; + maxScore = points; + } else if( points == maxScore ) { + if(element.length < word.length) { + word = element; + maxScore = points; + } + } + } + ); + return [word, maxScore]; +} + + + +console.log(highestScoreShortestWord(shortWordArray)) +console.log( '*** [ZAP, 14] ***') + +// ******************************** + module.exports = Scrabble; From d5bf6c371f668011240d330640a3caefea1da3a5 Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Wed, 16 Nov 2016 09:01:42 -0800 Subject: [PATCH 3/9] working wave 1, includes bonus scoring for 7-letter words --- scrabble.js | 113 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 36 deletions(-) diff --git a/scrabble.js b/scrabble.js index 329610e..ae19406 100644 --- a/scrabble.js +++ b/scrabble.js @@ -39,13 +39,17 @@ var shortWordArray = ["AEI", "MAP", "ZAP" ] var shortWordPointArray = [3, 7, 14] +var sevenWordArray = ['LOCKBOX', 'QUIZ', 'JAZZMEN', 'GATO', 'ZAP', 'JACUZZI', 'JAZZMAN'] + +var sevenWordPointArray = [72, 22, 5, 14, 84, 84] + // console.log(Tiles.A) -// score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. -// highestScoreFrom(arrayOfWords): returns the word in the array with the highest score. -// Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters. -// Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles. -// If the there are multiple words that are the same score and same length, pick the first one in supplied list. +// DONE ---- score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. +// DONE ---- highestScoreFrom(arrayOfWords): returns the word in the array with the highest score. +// DONE ---- Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters. +// DONE ---- Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles. +// DONE ---- If the there are multiple words that are the same score and same length, pick the first one in supplied list. var assign = function(letter) { @@ -55,13 +59,18 @@ var assign = function(letter) { // ******************************** var score = function(word) { - var wordScore = 0 - var ltr_array = word.split(''); - ltr_array.forEach(function(element) { - var point = assign(element); - wordScore += point; - }); - // console.log(wordScore); + if( word.length == 7 ) { + var wordScore = 50 } + + else wordScore = 0; + + var ltr_array = word.split( '' ); + + ltr_array.forEach(function( element ) { + var point = assign( element ); + wordScore += point;} + ); + return wordScore } @@ -71,13 +80,12 @@ console.log( '**** 5 ****' ) // ******************************** var showScores = function( array ) { - array.forEach(function(element) { - console.log(score(element)); - }); + array.forEach( function( element ) { + console.log( score( element ));}); } -showScores(wordArray) +showScores( wordArray ) console.log( '*****' + wordPointArray + '*****') // Scrabble.prototype.helloWorld = function() { // return 'hello world!'; @@ -86,15 +94,17 @@ console.log( '*****' + wordPointArray + '*****') // ******************************** var highestScore = function( array ) { var maxScore = 0 + var word = '' - array.forEach(function(element) { - var points = score(element); - if( points > maxScore ) { - word = element; - maxScore = points; - } - } - ); + + array.forEach( function( element ) { + var points = score( element ); + + if( points > maxScore ) { + word = element; + maxScore = points;} + }); + return word; } @@ -105,28 +115,59 @@ console.log( '***VACUUM***') var highestScoreShortestWord = function( array ) { var maxScore = 0 + var word = '' - array.forEach(function(element) { + + array.forEach( function( element ) { var points = score(element); - if( points > maxScore) { + + if( points > maxScore) { word = element; - maxScore = points; - } else if( points == maxScore ) { - if(element.length < word.length) { - word = element; - maxScore = points; - } + maxScore = points;} + + else if( points == maxScore ) { + if(element.length < word.length) { + word = element; + maxScore = points;} } - } - ); - return [word, maxScore]; + }); + + return [ word, maxScore ]; } -console.log(highestScoreShortestWord(shortWordArray)) +console.log(highestScoreShortestWord( shortWordArray )) console.log( '*** [ZAP, 14] ***') // ******************************** +var highestScoreShortestWordSevenLetters = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = score( element ); + + if( points > maxScore ) { + word = element; + maxScore = points;} + + else if( ( points == maxScore ) && ( element.length != word.length ) ) { + if( element.length == 7 ) { + word = element; + maxScore = points;} + + else if( ( element.length < word.length ) && ( word.length != 7 ) ) { + word = element; + maxScore = points;} + }; + }); + + return [ word, maxScore ]; +} + +console.log(highestScoreShortestWordSevenLetters(sevenWordArray)) +console.log( '*** [JAZZMEN, 84] ***') module.exports = Scrabble; From afba2efb5f18151d9db0103d77d249744afe374f Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Wed, 16 Nov 2016 09:01:53 -0800 Subject: [PATCH 4/9] start of wave 2 --- scrabble-wave2.js | 217 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 scrabble-wave2.js diff --git a/scrabble-wave2.js b/scrabble-wave2.js new file mode 100644 index 0000000..5f91b51 --- /dev/null +++ b/scrabble-wave2.js @@ -0,0 +1,217 @@ +var Scrabble = function() {}; + +// YOUR CODE HERE + +var Tiles = { + 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 +} + +var wordPointArray = [5, 10, 13] + +var wordArray = ["GATO", "RABBIT", "VACUUM"] + +var shortWordArray = ["AEI", "MAP", "ZAP" ] + +var shortWordPointArray = [3, 7, 14] + +var sevenWordArray = ['LOCKBOX', 'QUIZ', 'JAZZMEN', 'GATO', 'ZAP', 'JACUZZI', 'JAZZMAN'] + +var sevenWordPointArray = [72, 22, 5, 14, 84, 84] + +// console.log(Tiles.A) + +// DONE ---- score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. +// DONE ---- highestScoreFrom(arrayOfWords): returns the word in the array with the highest score. +// DONE ---- Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters. +// DONE ---- Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles. +// DONE ---- If the there are multiple words that are the same score and same length, pick the first one in supplied list. + + +var assign = function(letter) { + return Number(Tiles[letter]) +} + +// ******************************** + +var score = function(word) { + if( word.length == 7 ) { + var wordScore = 50 } + + else wordScore = 0; + + var ltr_array = word.split( '' ); + + ltr_array.forEach(function( element ) { + var point = assign( element ); + wordScore += point;} + ); + + return wordScore + } + +console.log(score('GATO')) +console.log( '**** 5 ****' ) + +// ******************************** + +var showScores = function( array ) { + array.forEach( function( element ) { + console.log( score( element ));}); +} + + +showScores( wordArray ) +console.log( '*****' + wordPointArray + '*****') +// Scrabble.prototype.helloWorld = function() { +// return 'hello world!'; +// }; + +// ******************************** +var highestScore = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = score( element ); + + if( points > maxScore ) { + word = element; + maxScore = points;} + }); + + return word; +} + +console.log(highestScore(wordArray)) +console.log( '***VACUUM***') + +// ******************************** + +var highestScoreShortestWord = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = score(element); + + if( points > maxScore) { + word = element; + maxScore = points;} + + else if( points == maxScore ) { + if(element.length < word.length) { + word = element; + maxScore = points;} + } + }); + + return [ word, maxScore ]; +} + + + +console.log(highestScoreShortestWord( shortWordArray )) +console.log( '*** [ZAP, 14] ***') + +// ******************************** + +var highestScoreShortestWordSevenLetters = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = score( element ); + + if( points > maxScore ) { + word = element; + maxScore = points;} + + else if( ( points == maxScore ) && ( element.length != word.length ) ) { + if( element.length == 7 ) { + word = element; + maxScore = points;} + + else if( ( element.length < word.length ) && ( word.length != 7 ) ) { + word = element; + maxScore = points;} + }; + }); + + return [ word, maxScore ]; +} + +console.log(highestScoreShortestWordSevenLetters(sevenWordArray)) +console.log( '*** [JAZZMEN, 84] ***') +module.exports = Scrabble; + + +// Wave 2 + +// Primary Requirements + +// Create a new Player object. The object should have the following functions: + +// Constructor: Called when you use new Player(name), sets up an instance with the instance variable name assigned +// name: property which returns the value of the player's name +// plays: property which returns an Array of the words played by the player +// play(word): Function which adds the input word to the plays Array +// Returns false if player has already won +// totalScore(): Function which sums up and returns the score of the players words +// hasWon(): Function which returns true if the player has over 100 points, otherwise returns false +// highestScoringWord(): Function which returns the highest scoring word the user has played +// highestWordScore(): Function which returns the highestScoringWord score + + +var Player.prototype = function( name ) { + this.name = function() { + return name }, + + plays = [], + + this.play = function( word ) { + this.plays << word }, + + this.hasWon = function() { + if( this.totalScore == 100 ) { + return true } + + else { return false }}, + + this.totalScore = function() +} + + + + + + + + From b50cea4fd869006352f2c1bd41ae762ae6701989 Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Wed, 16 Nov 2016 09:55:30 -0800 Subject: [PATCH 5/9] made Player constructor, added to Player prototype, change formatting of Player attributes, tested some attributes (name, play, plays) - totalScore not working yet --- scrabble-wave2.js | 60 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/scrabble-wave2.js b/scrabble-wave2.js index 5f91b51..333b2ca 100644 --- a/scrabble-wave2.js +++ b/scrabble-wave2.js @@ -59,6 +59,7 @@ var assign = function(letter) { // ******************************** var score = function(word) { + word = word.toUpperCase() if( word.length == 7 ) { var wordScore = 50 } @@ -179,8 +180,8 @@ module.exports = Scrabble; // Create a new Player object. The object should have the following functions: -// Constructor: Called when you use new Player(name), sets up an instance with the instance variable name assigned -// name: property which returns the value of the player's name +// DONE ---- Constructor: Called when you use new Player(name), sets up an instance with the instance variable name assigned +// DONE ---- name: property which returns the value of the player's name // plays: property which returns an Array of the words played by the player // play(word): Function which adds the input word to the plays Array // Returns false if player has already won @@ -190,28 +191,63 @@ module.exports = Scrabble; // highestWordScore(): Function which returns the highestScoringWord score -var Player.prototype = function( name ) { - this.name = function() { - return name }, +var Player = function( name ) { + this.name = name;} - plays = [], +Player.prototype = { + plays: [], - this.play = function( word ) { - this.plays << word }, + play: function( word ) { + // if( this.hasWon == true) { + // return false; } + // else + this.plays.push( word ); }, - this.hasWon = function() { + hasWon: function() { if( this.totalScore == 100 ) { - return true } + return true; } - else { return false }}, + else { return false; } }, - this.totalScore = function() + totalScore: function() { + var playerScore = 0; + + this.plays.forEach( function( element ) { + var points = score( element ); + playerScore += points; } ); + + // playerScore += score( element); + + + return playerScore;}, + + highestScoringWord: function( array ) { + var bestWordScoreArray = highestScoreShortestWordSevenLetters( plays ); + return bestWordScoreArray.filter(String); + }, + + highestWordScore: function( array ) { + var bestWordScoreArray = highestScoreShortestWordSevenLetters( plays ); + return bestWordScoreArray.filter(Number); + } } +sassa = new Player( 'Sassa ') + +console.log( sassa.name ) + +sassa.play( 'GATO' ) + + +sassa.play( 'quiz' ) +console.log( sassa.plays ) +console.log( '*** [GATO, quiz] ***') +console.log( sassa.totalScore ) +console.log( '*** 27 ***') From b0a35c468cf179cefdd8f1aaf10ca38d21a19d51 Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Wed, 16 Nov 2016 15:11:08 -0800 Subject: [PATCH 6/9] working wave 2 --- scrabble-wave2.js | 263 ++++++++++++++++++++++++---------------------- 1 file changed, 138 insertions(+), 125 deletions(-) diff --git a/scrabble-wave2.js b/scrabble-wave2.js index 333b2ca..227c653 100644 --- a/scrabble-wave2.js +++ b/scrabble-wave2.js @@ -1,105 +1,110 @@ -var Scrabble = function() {}; - -// YOUR CODE HERE - -var Tiles = { - 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 -} +// DONE ---- score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. +// DONE ---- highestScoreFrom(arrayOfWords): returns the word in the array with the highest score. +// DONE ---- Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters. +// DONE ---- Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles. +// DONE ---- If the there are multiple words that are the same score and same length, pick the first one in supplied list. -var wordPointArray = [5, 10, 13] +// ARRAYS FOR TESTING +wordPointArray = [5, 10, 13] -var wordArray = ["GATO", "RABBIT", "VACUUM"] +wordArray = ["GATO", "RABBIT", "VACUUM"] -var shortWordArray = ["AEI", "MAP", "ZAP" ] +shortWordArray = ["AEI", "MAP", "ZAP" ] -var shortWordPointArray = [3, 7, 14] +shortWordPointArray = [3, 7, 14] -var sevenWordArray = ['LOCKBOX', 'QUIZ', 'JAZZMEN', 'GATO', 'ZAP', 'JACUZZI', 'JAZZMAN'] +sevenWordArray = ['LOCKBOX', 'QUIZ', 'JAZZMEN', 'GATO', 'ZAP', 'JACUZZI', 'JAZZMAN'] -var sevenWordPointArray = [72, 22, 5, 14, 84, 84] +sevenWordPointArray = [72, 22, 5, 14, 84, 84] -// console.log(Tiles.A) + // /ARRAYS FOR TESTING -// DONE ---- score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. -// DONE ---- highestScoreFrom(arrayOfWords): returns the word in the array with the highest score. -// DONE ---- Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters. -// DONE ---- Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles. -// DONE ---- If the there are multiple words that are the same score and same length, pick the first one in supplied list. + +var Scrabble = function() {} + +Scrabble.letterPoints = { + 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 }; -var assign = function(letter) { - return Number(Tiles[letter]) -} -// ******************************** +maggie = new Scrabble() +// console.log( Scrabble.letterPoints ); -var score = function(word) { - word = word.toUpperCase() - if( word.length == 7 ) { - var wordScore = 50 } +// console.log( Scrabble.letterPoints.A ); - else wordScore = 0; - var ltr_array = word.split( '' ); - ltr_array.forEach(function( element ) { - var point = assign( element ); - wordScore += point;} +Scrabble.assign = function(letter) { + return Number( Scrabble.letterPoints[ letter ] ); + }; + +Scrabble.score = function(word) { + word = word.toUpperCase(); + + if( word.length == 7 ) { + var wordScore = 50 } + + else wordScore = 0; + + var ltr_array = word.split( '' ); + + ltr_array.forEach( function( element ) { + wordScore += Scrabble.assign( element );} ); - return wordScore - } - -console.log(score('GATO')) -console.log( '**** 5 ****' ) + return wordScore; +}; + +// sassa = new Scrabble(); +// console.log( Scrabble.score('GATO')); +// console.log( '**** 5 ****' ) + +// // ******************************** -// ******************************** +Scrabble.showScores = function( array ) { -var showScores = function( array ) { array.forEach( function( element ) { - console.log( score( element ));}); -} + console.log( Scrabble.score( element ));}); +}; + +// Scrabble.showScores( wordArray ); +// console.log( '*****' + wordPointArray + '*****'); -showScores( wordArray ) -console.log( '*****' + wordPointArray + '*****') -// Scrabble.prototype.helloWorld = function() { -// return 'hello world!'; -// }; -// ******************************** -var highestScore = function( array ) { +// // ******************************** +Scrabble.highestScore = function( array ) { var maxScore = 0 var word = '' array.forEach( function( element ) { - var points = score( element ); + var points = Scrabble.score( element ); if( points > maxScore ) { word = element; @@ -109,27 +114,27 @@ var highestScore = function( array ) { return word; } -console.log(highestScore(wordArray)) +console.log( Scrabble.highestScore( wordArray ) ) console.log( '***VACUUM***') -// ******************************** +// // ******************************** -var highestScoreShortestWord = function( array ) { +Scrabble.highestScoreShortestWord = function( array ) { var maxScore = 0 var word = '' - + array.forEach( function( element ) { - var points = score(element); + var points = Scrabble.score(element); - if( points > maxScore) { + if( points > maxScore ) { word = element; - maxScore = points;} + maxScore = points; } else if( points == maxScore ) { - if(element.length < word.length) { + if( element.length < word.length ) { word = element; - maxScore = points;} + maxScore = points; } } }); @@ -138,18 +143,18 @@ var highestScoreShortestWord = function( array ) { -console.log(highestScoreShortestWord( shortWordArray )) +console.log( Scrabble.highestScoreShortestWord( shortWordArray )) console.log( '*** [ZAP, 14] ***') -// ******************************** +// // ******************************** -var highestScoreShortestWordSevenLetters = function( array ) { +Scrabble.highestScoreShortestWordSevenLetters = function( array ) { var maxScore = 0 var word = '' array.forEach( function( element ) { - var points = score( element ); + var points = Scrabble.score( element ); if( points > maxScore ) { word = element; @@ -169,8 +174,10 @@ var highestScoreShortestWordSevenLetters = function( array ) { return [ word, maxScore ]; } -console.log(highestScoreShortestWordSevenLetters(sevenWordArray)) +console.log( Scrabble.highestScoreShortestWordSevenLetters( sevenWordArray ) ) console.log( '*** [JAZZMEN, 84] ***') + + module.exports = Scrabble; @@ -182,55 +189,45 @@ module.exports = Scrabble; // DONE ---- Constructor: Called when you use new Player(name), sets up an instance with the instance variable name assigned // DONE ---- name: property which returns the value of the player's name -// plays: property which returns an Array of the words played by the player -// play(word): Function which adds the input word to the plays Array +// DONE plays: property which returns an Array of the words played by the player +// DONE play(word): Function which adds the input word to the plays Array // Returns false if player has already won -// totalScore(): Function which sums up and returns the score of the players words -// hasWon(): Function which returns true if the player has over 100 points, otherwise returns false -// highestScoringWord(): Function which returns the highest scoring word the user has played -// highestWordScore(): Function which returns the highestScoringWord score +// DONE totalScore(): Function which sums up and returns the score of the players words +// DONE hasWon(): Function which returns true if the player has over 100 points, otherwise returns false +// DONE highestScoringWord(): Function which returns the highest scoring word the user has played +// DONE highestWordScore(): Function which returns the highestScoringWord score var Player = function( name ) { - this.name = name;} - -Player.prototype = { - plays: [], - - play: function( word ) { - // if( this.hasWon == true) { - // return false; } - // else - this.plays.push( word ); }, + this.name = name, + this.plays = []}; - hasWon: function() { - if( this.totalScore == 100 ) { - return true; } +Player.prototype.play = function( word ) { + console.log( 'doing something ' + word ); + this.plays.push( word ); + return this.hasWon(); }; - else { return false; } }, +Player.prototype.hasWon = function() { + return this.totalScore() >= 100 }; - totalScore: function() { - var playerScore = 0; +Player.prototype.totalScore = function() { + var playerScore = 20; this.plays.forEach( function( element ) { - var points = score( element ); - playerScore += points; } ); - - // playerScore += score( element); + playerScore += Scrabble.score( element ) } ); + return playerScore;}; - return playerScore;}, +Player.prototype.highestScoringWord = function( array ) { + var bestWordScoreArray = Scrabble.highestScoreShortestWordSevenLetters( this.plays ); + return bestWordScoreArray[0]; + }; - highestScoringWord: function( array ) { - var bestWordScoreArray = highestScoreShortestWordSevenLetters( plays ); - return bestWordScoreArray.filter(String); - }, +Player.prototype.highestWordScore = function( array ) { + var bestWordScoreArray = Scrabble.highestScoreShortestWordSevenLetters( this.plays ); + return bestWordScoreArray[1]; + }; - highestWordScore: function( array ) { - var bestWordScoreArray = highestScoreShortestWordSevenLetters( plays ); - return bestWordScoreArray.filter(Number); - } -} sassa = new Player( 'Sassa ') @@ -245,9 +242,25 @@ console.log( sassa.plays ) console.log( '*** [GATO, quiz] ***') -console.log( sassa.totalScore ) + +console.log( sassa.totalScore() ) console.log( '*** 27 ***') +console.log( sassa.highestScoringWord() ) + +console.log( '*** quiz ***') + +console.log( sassa.highestWordScore()) +console.log( '*** 22 ***') + +console.log( sassa.totalScore() ) + +console.log( sassa.play( 'WIN' ) ) + +console.log( sassa.totalScore() ) + +console.log( sassa.plays ) +console.log( sassa.totalScore() ) \ No newline at end of file From 4b01ba7c9a3876aa95c4bf7662bed83e079295ec Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Wed, 16 Nov 2016 15:11:31 -0800 Subject: [PATCH 7/9] first run, everything scrabble outside of scrabble, mistake --- scrabble-wave2-global-method-mistake.js | 252 ++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 scrabble-wave2-global-method-mistake.js diff --git a/scrabble-wave2-global-method-mistake.js b/scrabble-wave2-global-method-mistake.js new file mode 100644 index 0000000..d99a786 --- /dev/null +++ b/scrabble-wave2-global-method-mistake.js @@ -0,0 +1,252 @@ +var Scrabble = function() {}; + +// YOUR CODE HERE + +var Tiles = { + 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 +} + +var wordPointArray = [5, 10, 13] + +var wordArray = ["GATO", "RABBIT", "VACUUM"] + +var shortWordArray = ["AEI", "MAP", "ZAP" ] + +var shortWordPointArray = [3, 7, 14] + +var sevenWordArray = ['LOCKBOX', 'QUIZ', 'JAZZMEN', 'GATO', 'ZAP', 'JACUZZI', 'JAZZMAN'] + +var sevenWordPointArray = [72, 22, 5, 14, 84, 84] + +// console.log(Tiles.A) + +// DONE ---- score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. +// DONE ---- highestScoreFrom(arrayOfWords): returns the word in the array with the highest score. +// DONE ---- Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters. +// DONE ---- Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles. +// DONE ---- If the there are multiple words that are the same score and same length, pick the first one in supplied list. + + +var assign = function(letter) { + return Number(Tiles[letter]) +} + +// ******************************** + +var score = function(word) { + word = word.toUpperCase() + if( word.length == 7 ) { + var wordScore = 50 } + + else wordScore = 0; + + var ltr_array = word.split( '' ); + + ltr_array.forEach(function( element ) { + var point = assign( element ); + wordScore += point;} + ); + + return wordScore + } + +console.log(score('GATO')) +console.log( '**** 5 ****' ) + +// ******************************** + +var showScores = function( array ) { + array.forEach( function( element ) { + console.log( score( element ));}); +} + + +showScores( wordArray ) +console.log( '*****' + wordPointArray + '*****') +// Scrabble.prototype.helloWorld = function() { +// return 'hello world!'; +// }; + +// ******************************** +var highestScore = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = score( element ); + + if( points > maxScore ) { + word = element; + maxScore = points;} + }); + + return word; +} + +console.log(highestScore(wordArray)) +console.log( '***VACUUM***') + +// ******************************** + +var highestScoreShortestWord = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = score(element); + + if( points > maxScore) { + word = element; + maxScore = points;} + + else if( points == maxScore ) { + if(element.length < word.length) { + word = element; + maxScore = points;} + } + }); + + return [ word, maxScore ]; +} + + + +console.log(highestScoreShortestWord( shortWordArray )) +console.log( '*** [ZAP, 14] ***') + +// ******************************** + +var highestScoreShortestWordSevenLetters = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = score( element ); + + if( points > maxScore ) { + word = element; + maxScore = points;} + + else if( ( points == maxScore ) && ( element.length != word.length ) ) { + if( element.length == 7 ) { + word = element; + maxScore = points;} + + else if( ( element.length < word.length ) && ( word.length != 7 ) ) { + word = element; + maxScore = points;} + }; + }); + + return [ word, maxScore ]; +} + +console.log(highestScoreShortestWordSevenLetters(sevenWordArray)) +console.log( '*** [JAZZMEN, 84] ***') +module.exports = Scrabble; + + +// Wave 2 + +// Primary Requirements + +// Create a new Player object. The object should have the following functions: + +// DONE ---- Constructor: Called when you use new Player(name), sets up an instance with the instance variable name assigned +// DONE ---- name: property which returns the value of the player's name +// plays: property which returns an Array of the words played by the player +// play(word): Function which adds the input word to the plays Array +// Returns false if player has already won +// totalScore(): Function which sums up and returns the score of the players words +// hasWon(): Function which returns true if the player has over 100 points, otherwise returns false +// highestScoringWord(): Function which returns the highest scoring word the user has played +// highestWordScore(): Function which returns the highestScoringWord score + + +var Player = function( name ) { + this.name = name;} + +Player.prototype = { + plays: [], + + play: function( word ) { + // if( this.hasWon == true) { + // return false; } + // else + this.plays.push( word ); }, + + hasWon: function() { + if( this.totalScore == 100 ) { + return true; } + + else { return false; } }, + + totalScore: function() { + var playerScore = 0; + + this.plays.forEach( function( element ) { + playerScore += score( element ) } ); + + return playerScore;}, + + highestScoringWord: function( array ) { + var bestWordScoreArray = highestScoreShortestWordSevenLetters( this.plays ); + return bestWordScoreArray[0]; + }, + + highestWordScore: function( array ) { + var bestWordScoreArray = highestScoreShortestWordSevenLetters( this.plays ); + return bestWordScoreArray[1]; + } +} + +sassa = new Player( 'Sassa ') + +console.log( sassa.name ) + +sassa.play( 'GATO' ) + + +sassa.play( 'quiz' ) + +console.log( sassa.plays ) + +console.log( '*** [GATO, quiz] ***') + + +console.log( sassa.totalScore() ) + +console.log( '*** 27 ***') + +console.log( sassa.highestScoringWord() ) + +console.log( sassa.highestWordScore()) + From baec4180c127cc9cc5b3490d86491e35cae5e063 Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Thu, 17 Nov 2016 23:05:54 -0800 Subject: [PATCH 8/9] trying for optionals --- scrabble-wave12opts.js | 308 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 scrabble-wave12opts.js diff --git a/scrabble-wave12opts.js b/scrabble-wave12opts.js new file mode 100644 index 0000000..0c8128d --- /dev/null +++ b/scrabble-wave12opts.js @@ -0,0 +1,308 @@ +// DONE ---- score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter. +// DONE ---- highestScoreFrom(arrayOfWords): returns the word in the array with the highest score. +// DONE ---- Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters. +// DONE ---- Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles. +// DONE ---- If the there are multiple words that are the same score and same length, pick the first one in supplied list. + +// ARRAYS FOR TESTING +wordPointArray = [5, 10, 13] + +wordArray = ["GATO", "RABBIT", "VACUUM"] + +shortWordArray = ["AEI", "MAP", "ZAP" ] + +shortWordPointArray = [3, 7, 14] + +sevenWordArray = ['LOCKBOX', 'QUIZ', 'JAZZMEN', 'GATO', 'ZAP', 'JACUZZI', 'JAZZMAN'] + +sevenWordPointArray = [72, 22, 5, 14, 84, 84] + + // /ARRAYS FOR TESTING + + +var Scrabble = function() {} + +Scrabble.letterPoints = { + 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 }; + + + +maggie = new Scrabble() +// console.log( Scrabble.letterPoints ); + +// console.log( Scrabble.letterPoints.A ); + + + +Scrabble.assign = function(letter) { + return Number( Scrabble.letterPoints[ letter ] ); + }; + +Scrabble.score = function(word) { + word = word.toUpperCase(); + + if( word.length == 7 ) { + var wordScore = 50 } + + else wordScore = 0; + + var ltr_array = word.split( '' ); + + ltr_array.forEach( function( element ) { + wordScore += Scrabble.assign( element );} + ); + + return wordScore; +}; + +// sassa = new Scrabble(); +// console.log( Scrabble.score('GATO')); +// console.log( '**** 5 ****' ) + +// // ******************************** + +Scrabble.showScores = function( array ) { + + array.forEach( function( element ) { + console.log( Scrabble.score( element ));}); +}; + + +// Scrabble.showScores( wordArray ); +// console.log( '*****' + wordPointArray + '*****'); + + +// // ******************************** +Scrabble.highestScore = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = Scrabble.score( element ); + + if( points > maxScore ) { + word = element; + maxScore = points;} + }); + + return word; +} + +// console.log( Scrabble.highestScore( wordArray ) ) +// console.log( '***VACUUM***') + +// // ******************************** + +Scrabble.highestScoreShortestWord = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = Scrabble.score(element); + + if( points > maxScore ) { + word = element; + maxScore = points; } + + else if( points == maxScore ) { + if( element.length < word.length ) { + word = element; + maxScore = points; } + } + }); + + return [ word, maxScore ]; +} + + + +// console.log( Scrabble.highestScoreShortestWord( shortWordArray )) +// console.log( '*** [ZAP, 14] ***') + +// // ******************************** + +Scrabble.highestScoreShortestWordSevenLetters = function( array ) { + var maxScore = 0 + + var word = '' + + array.forEach( function( element ) { + var points = Scrabble.score( element ); + + if( points > maxScore ) { + word = element; + maxScore = points;} + + else if( ( points == maxScore ) && ( element.length != word.length ) ) { + if( element.length == 7 ) { + word = element; + maxScore = points;} + + else if( ( element.length < word.length ) && ( word.length != 7 ) ) { + word = element; + maxScore = points;} + }; + }); + + return [ word, maxScore ]; +} + +// console.log( Scrabble.highestScoreShortestWordSevenLetters( sevenWordArray ) ) +// console.log( '*** [JAZZMEN, 84] ***') + + +module.exports = Scrabble; + + +// Wave 2 + +// Primary Requirements + +// Create a new Player object. The object should have the following functions: + +// DONE ---- Constructor: Called when you use new Player(name), sets up an instance with the instance variable name assigned +// DONE ---- name: property which returns the value of the player's name +// DONE plays: property which returns an Array of the words played by the player +// DONE play(word): Function which adds the input word to the plays Array +// Returns false if player has already won +// DONE totalScore(): Function which sums up and returns the score of the players words +// DONE hasWon(): Function which returns true if the player has over 100 points, otherwise returns false +// DONE highestScoringWord(): Function which returns the highest scoring word the user has played +// DONE highestWordScore(): Function which returns the highestScoringWord score + + +var Player = function( name ) { + this.name = name, + this.plays = []}; + +Player.prototype.play = function( word ) { + console.log( 'doing something ' + word ); + this.plays.push( word ); + return this.hasWon(); }; + +Player.prototype.hasWon = function() { + return this.totalScore() >= 100 }; + +Player.prototype.totalScore = function() { + var playerScore = 20; + + this.plays.forEach( function( element ) { + playerScore += Scrabble.score( element ) } ); + + return playerScore;}; + +Player.prototype.highestScoringWord = function( array ) { + var bestWordScoreArray = Scrabble.highestScoreShortestWordSevenLetters( this.plays ); + return bestWordScoreArray[0]; + }; + +Player.prototype.highestWordScore = function( array ) { + var bestWordScoreArray = Scrabble.highestScoreShortestWordSevenLetters( this.plays ); + return bestWordScoreArray[1]; + }; + + +// sassa = new Player( 'Sassa ') + +// console.log( sassa.name ) + +// sassa.play( 'GATO' ) + + +// sassa.play( 'quiz' ) + +// console.log( sassa.plays ) + +// console.log( '*** [GATO, quiz] ***') + + +// console.log( sassa.totalScore() ) + +// console.log( '*** 27 ***') + +// console.log( sassa.highestScoringWord() ) + +// console.log( '*** quiz ***') + +// console.log( sassa.highestWordScore()) + +// console.log( '*** 22 ***') + +// console.log( sassa.totalScore() ) + +// console.log( sassa.play( 'WIN' ) ) + +// console.log( sassa.totalScore() ) + +// console.log( sassa.plays ) + +// console.log( sassa.totalScore() ) + + +var TileBag = function() {} + +TileBag.prototype.tiles = { + A: 9, + E: 12, + I: 9, + O: 8, + U: 4, + L: 1, + N: 6, + R: 6, + S: 4, + T: 6, + D: 4, + G: 3, + B: 2, + C: 2, + M: 2, + P: 2, + F: 2, + H: 2, + V: 2, + W: 2, + Y: 2, + K: 1, + J: 1, + X: 1, + Q: 1, + Z: 1 }; + + +var TileBag.drawTiles = function( letter ) { + map.put(TileBag[ letter ], map.get(TileBag[ letter ]) -1 ); +} + +test = new TileBag + +console.log( test.tiles ) + + From e9f7150e90590b7b21b30f7f51d031037392ec1d Mon Sep 17 00:00:00 2001 From: RedSquirrelious Date: Fri, 18 Nov 2016 09:39:24 -0800 Subject: [PATCH 9/9] added hasWon functionality to playmethod --- scrabble-wave2.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scrabble-wave2.js b/scrabble-wave2.js index 227c653..3c076da 100644 --- a/scrabble-wave2.js +++ b/scrabble-wave2.js @@ -203,9 +203,11 @@ var Player = function( name ) { this.plays = []}; Player.prototype.play = function( word ) { - console.log( 'doing something ' + word ); - this.plays.push( word ); - return this.hasWon(); }; + if (this.hasWon == true){ + this.plays.push( word ); + return this.hasWon(); } + else { + return false;}}; Player.prototype.hasWon = function() { return this.totalScore() >= 100 };