From 8827c8421599dc832c0caaa47423eec63c187e0a Mon Sep 17 00:00:00 2001 From: Beylul Date: Wed, 16 Nov 2016 17:25:07 -0800 Subject: [PATCH 1/5] added score function --- scrabble.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/scrabble.js b/scrabble.js index a7d0745..305b76a 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,8 +1,33 @@ var Scrabble = function() {}; +//global variable letterscore +letterScore = {"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}; -// YOUR CODE HERE -Scrabble.prototype.helloWorld = function() { - return 'hello world!'; +//function score that is prototype of Scrabble +Scrabble.prototype.score = function(word) { + word = word.toUpperCase(); + this.word = word.split(""); + var score = 0; + if (this.word.length == 7) { + score = 50; + } + this.word.forEach(function(i) { + score += letterScore[i]; + }); + return score; }; -module.exports = Scrabble; +//new scrabble object +var scrabble = new Scrabble(); + +//testing +console.log(scrabble.score("abc")); + + +// YOUR CODE HERE +// Scrabble.prototype.helloWorld = function() { +// return 'hello world!'; +// }; +// module.exports = Scrabble; +// +// scrabb = new Scrabble; +// console.log(scrabb.helloWorld()); From d406ad35ad317822b7a7f8a29ec3fde46182552a Mon Sep 17 00:00:00 2001 From: Beylul Date: Wed, 16 Nov 2016 23:09:54 -0800 Subject: [PATCH 2/5] finished with highstscoreForm --- scrabble.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/scrabble.js b/scrabble.js index 305b76a..964e117 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,12 +1,12 @@ var Scrabble = function() {}; //global variable letterscore -letterScore = {"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}; +letterScore = {"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}; //function score that is prototype of Scrabble Scrabble.prototype.score = function(word) { word = word.toUpperCase(); this.word = word.split(""); - var score = 0; + var score = 0; if (this.word.length == 7) { score = 50; } @@ -16,11 +16,58 @@ Scrabble.prototype.score = function(word) { return score; }; + + +Scrabble.prototype.highestScoreFrom = function(arrayOfWords) +{ + this.arrayOfWords = arrayOfWords; + var scoredWords = []; + var highestScore = 0; + + for (var i = 0; i < arrayOfWords.length; i++) { + var word = arrayOfWords[i]; + var scoredInt = this.score(word); + + if(highestScore < scoredInt){ + highestScore = scoredInt; + scoredWords.push(word); + + // console.log(highestScore); + } + + // console.log(highestScore); + // if(scoredWords.scoredInt === undefined) + // { + // scoredWords.scoredInt = [word]; + // console.log(scoredWords); + // } + // else + // { + // scoredWords.scoredInt.push(word); + // + // } + // } + // scoredWords.push(word); + // console.log(highestScore); + // if(scoredWords.length > 1) + // { + // scoredWords.sort(function(a, b ) { + // return b.length - a.length; + // }); + // } +} + // return scoredWords.highestScore[0]; + return(scoredWords[scoredWords.length - 1]); +}; + //new scrabble object var scrabble = new Scrabble(); - -//testing -console.log(scrabble.score("abc")); +console.log(scrabble.highestScoreFrom(["iiiiiii","aaa", "asefr", "aer", "aserd", "aaaaaaa"])); +console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "aaaaaaa", "iiiiiii"])); +console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "aaaaaaa", "zzzzzz"])); +// +// //testing +// console.log(scrabble.score("abc")); // YOUR CODE HERE From eeeae78423171141fc213bc295490e8960c31b90 Mon Sep 17 00:00:00 2001 From: Beylul Date: Thu, 17 Nov 2016 06:31:09 -0800 Subject: [PATCH 3/5] fixed highscore to account for multiple words with the same score --- scrabble.js | 98 ++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/scrabble.js b/scrabble.js index 964e117..f6d9b1e 100644 --- a/scrabble.js +++ b/scrabble.js @@ -16,65 +16,65 @@ Scrabble.prototype.score = function(word) { return score; }; - - Scrabble.prototype.highestScoreFrom = function(arrayOfWords) { this.arrayOfWords = arrayOfWords; var scoredWords = []; var highestScore = 0; - for (var i = 0; i < arrayOfWords.length; i++) { - var word = arrayOfWords[i]; + for (var i = 0; i < arrayOfWords.length; i++) { + var word = arrayOfWords[i]; var scoredInt = this.score(word); - - if(highestScore < scoredInt){ + if (highestScore <= scoredInt){ highestScore = scoredInt; - scoredWords.push(word); - - // console.log(highestScore); - } + } + } + for (var i = 0; i < arrayOfWords.length; i++) { + var word = arrayOfWords[i]; + var scoredInt = this.score(word); + if(scoredInt == highestScore){ + scoredWords.push(word); + } + } - // console.log(highestScore); - // if(scoredWords.scoredInt === undefined) - // { - // scoredWords.scoredInt = [word]; - // console.log(scoredWords); - // } - // else - // { - // scoredWords.scoredInt.push(word); - // - // } - // } - // scoredWords.push(word); - // console.log(highestScore); - // if(scoredWords.length > 1) - // { - // scoredWords.sort(function(a, b ) { - // return b.length - a.length; - // }); - // } -} - // return scoredWords.highestScore[0]; - return(scoredWords[scoredWords.length - 1]); + if(scoredWords.length > 1) + { + scoredWords.sort(function(a, b ) { + return b.length - a.length; + }); + if ((scoredWords[0].length)==7) { + return scoredWords[0]; + } else{ + return(scoredWords[scoredWords.length - 1]); + } + } + else{ + return scoredWords[0]; + } }; -//new scrabble object -var scrabble = new Scrabble(); -console.log(scrabble.highestScoreFrom(["iiiiiii","aaa", "asefr", "aer", "aserd", "aaaaaaa"])); -console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "aaaaaaa", "iiiiiii"])); -console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "aaaaaaa", "zzzzzz"])); -// -// //testing -// console.log(scrabble.score("abc")); + //new scrabble object + var scrabble = new Scrabble(); + console.log(scrabble.highestScoreFrom(["iiiiiii","aaa", "asefr", "aer", "aserd", "aaaaaaa", "iiiiiid"])); + console.log(scrabble.highestScoreFrom(["dd","iiii"])); + console.log(scrabble.highestScoreFrom(["iiii","dd"])); + + console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "iiiiiii", "aaaaaaa"])); + console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd","aaaaaaa", "iiiiiii"])); + console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "aaaaaaa", "zzzzz"])); + // + // //testing + console.log(scrabble.score("iiiiiid")); + console.log(scrabble.score("iiiiiii")); + console.log(scrabble.score("aaaaaaa")); + console.log(scrabble.score("zzzzz")); -// YOUR CODE HERE -// Scrabble.prototype.helloWorld = function() { -// return 'hello world!'; -// }; -// module.exports = Scrabble; -// -// scrabb = new Scrabble; -// console.log(scrabb.helloWorld()); + // YOUR CODE HERE + // Scrabble.prototype.helloWorld = function() { + // return 'hello world!'; + // }; + // module.exports = Scrabble; + // + // scrabb = new Scrabble; + // console.log(scrabb.helloWorld()); From 9f2b4a0b8f90e2a902b1d762d66d2afbad6dac33 Mon Sep 17 00:00:00 2001 From: Beylul Date: Thu, 17 Nov 2016 14:06:31 -0800 Subject: [PATCH 4/5] added wave two methods --- scrabble.js | 140 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 104 insertions(+), 36 deletions(-) diff --git a/scrabble.js b/scrabble.js index f6d9b1e..e5f9be9 100644 --- a/scrabble.js +++ b/scrabble.js @@ -4,7 +4,7 @@ letterScore = {"A": 1, "B": 3, "C": 3, "D": 2, "E": 1, "F": 4, "G": 2, "H": 4, " //function score that is prototype of Scrabble Scrabble.prototype.score = function(word) { - word = word.toUpperCase(); + word = word.toLowerCase(); this.word = word.split(""); var score = 0; if (this.word.length == 7) { @@ -25,56 +25,124 @@ Scrabble.prototype.highestScoreFrom = function(arrayOfWords) for (var i = 0; i < arrayOfWords.length; i++) { var word = arrayOfWords[i]; var scoredInt = this.score(word); - if (highestScore <= scoredInt){ + if (highestScore <= scoredInt){ highestScore = scoredInt; - } + } } + for (var i = 0; i < arrayOfWords.length; i++) { var word = arrayOfWords[i]; var scoredInt = this.score(word); - if(scoredInt == highestScore){ - scoredWords.push(word); - } - } + if(scoredInt == highestScore){ + scoredWords.push(word); + } + } if(scoredWords.length > 1) { scoredWords.sort(function(a, b ) { - return b.length - a.length; + return b.length - a.length; }); if ((scoredWords[0].length)==7) { return scoredWords[0]; } else{ - return(scoredWords[scoredWords.length - 1]); - } + return(scoredWords[scoredWords.length - 1]); + } } else{ - return scoredWords[0]; + return scoredWords[0]; + } +}; + +var Player = function(name){ + this.name = name; + this.plays =[]; + scrabble = new Scrabble; +}; +Player.prototype.play = function(word) { + if (this.hasWon()===false){ + this.plays.push(word); } + else { + return false; + } + // console.log(this.plays) +}; +// console.log(Player.play) + +Player.prototype.totalScore = function() { + var totalScore = 0; + for(var i = 0; i < this.plays.length; i++){ + totalScore +=scrabble.score(this.plays[i]); + // console.log(scrabble.score(this.plays[i])); + // console.log(this.plays); + // console.log(totalScore); + } + return totalScore; + // console.log(totalScore); }; - //new scrabble object - var scrabble = new Scrabble(); - console.log(scrabble.highestScoreFrom(["iiiiiii","aaa", "asefr", "aer", "aserd", "aaaaaaa", "iiiiiid"])); - console.log(scrabble.highestScoreFrom(["dd","iiii"])); - console.log(scrabble.highestScoreFrom(["iiii","dd"])); - - console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "iiiiiii", "aaaaaaa"])); - console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd","aaaaaaa", "iiiiiii"])); - console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "aaaaaaa", "zzzzz"])); - // - // //testing - console.log(scrabble.score("iiiiiid")); - console.log(scrabble.score("iiiiiii")); - console.log(scrabble.score("aaaaaaa")); - console.log(scrabble.score("zzzzz")); - - - // YOUR CODE HERE - // Scrabble.prototype.helloWorld = function() { - // return 'hello world!'; - // }; - // module.exports = Scrabble; - // - // scrabb = new Scrabble; - // console.log(scrabb.helloWorld()); +Player.prototype.hasWon = function(){ + if (this.totalScore() > 100){ + return true; + } + else { + return false; + + } +}; + +Player.prototype.highestScoringWord = function(){ + var highstWordScored = scrabble.highestScoreFrom(this.plays); + return highstWordScored; +}; + +Player.prototype.highestWordScore = function(){ + var highstScore = scrabble.score(this.highestScoringWord); + return highstScore; + // console.log(highstScore); +}; + + +var player = new Player("Beylul"); +console.log(player.plays); +console.log(player.play("word")); +console.log(player.plays); +// console.log(player.totalScore()); +// console.log(player.plays); +// console.log(player.hasWon()); +// console.log(player.play("zzzzzzz")); +// console.log(player.play("zzzzzzz")); +// console.log(player.totalScore()); +// console.log(player.hasWon()); +// console.log(player.highestScoringWord()); +// console.log(player.highestWordScore()); + + + + +// //testing score highestScoreFrom +// var scrabble = new Scrabble(); +// console.log(scrabble.highestScoreFrom(["iiiiiii","aaa", "asefr", "aer", "aserd", "aaaaaaa", "iiiiiid"])); +// console.log(scrabble.highestScoreFrom(["dd","iiii"])); +// console.log(scrabble.highestScoreFrom(["iiii","dd"])); +// +// console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "iiiiiii", "aaaaaaa"])); +// console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd","aaaaaaa", "iiiiiii"])); +// console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "aaaaaaa", "zzzzz"])); +// +// //testing score +// console.log(scrabble.score("iiiiiid")); +// console.log(scrabble.score("iiiiiii")); +// console.log(scrabble.score("aaaaaaa")); +// console.log(scrabble.score("zzzzz")); + + +// YOUR CODE HERE +// Scrabble.prototype.helloWorld = function() { +// return 'hello world!'; +// }; +// module.exports = Scrabble; +// +// scrabb = new Scrabble; +// console.log(scrabb.helloWorld()); From fa011985770235052410f893e959260835e2243d Mon Sep 17 00:00:00 2001 From: Beylul Date: Fri, 18 Nov 2016 08:45:20 -0800 Subject: [PATCH 5/5] cleanded up the project --- scrabble.js | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/scrabble.js b/scrabble.js index e5f9be9..bbbb804 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,10 +1,9 @@ var Scrabble = function() {}; -//global variable letterscore -letterScore = {"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}; - -//function score that is prototype of Scrabble Scrabble.prototype.score = function(word) { - word = word.toLowerCase(); + var letterScore = {"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}; + + word = word.toUpperCase(); + this.word = word.split(""); var score = 0; if (this.word.length == 7) { @@ -57,8 +56,9 @@ Scrabble.prototype.highestScoreFrom = function(arrayOfWords) var Player = function(name){ this.name = name; this.plays =[]; - scrabble = new Scrabble; + this.scrabble = new Scrabble(); }; + Player.prototype.play = function(word) { if (this.hasWon()===false){ this.plays.push(word); @@ -66,20 +66,15 @@ Player.prototype.play = function(word) { else { return false; } - // console.log(this.plays) }; -// console.log(Player.play) Player.prototype.totalScore = function() { var totalScore = 0; for(var i = 0; i < this.plays.length; i++){ - totalScore +=scrabble.score(this.plays[i]); - // console.log(scrabble.score(this.plays[i])); - // console.log(this.plays); - // console.log(totalScore); + totalScore += this.scrabble.score(this.plays[i]); + console.log(this.scrabble.score(this.plays[i])); } return totalScore; - // console.log(totalScore); }; Player.prototype.hasWon = function(){ @@ -88,30 +83,29 @@ Player.prototype.hasWon = function(){ } else { return false; - } }; Player.prototype.highestScoringWord = function(){ - var highstWordScored = scrabble.highestScoreFrom(this.plays); + var highstWordScored = this.scrabble.highestScoreFrom(this.plays); return highstWordScored; }; Player.prototype.highestWordScore = function(){ - var highstScore = scrabble.score(this.highestScoringWord); + var highstScore = this.scrabble.score(this.highestScoringWord()); return highstScore; - // console.log(highstScore); }; - -var player = new Player("Beylul"); -console.log(player.plays); -console.log(player.play("word")); -console.log(player.plays); +//testing player +// var player = new Player("Beylul"); +// console.log(player.plays); +// console.log(player.play("word")); +// console.log(player.plays); // console.log(player.totalScore()); // console.log(player.plays); // console.log(player.hasWon()); // console.log(player.play("zzzzzzz")); +// console.log(player.plays); // console.log(player.play("zzzzzzz")); // console.log(player.totalScore()); // console.log(player.hasWon()); @@ -130,8 +124,8 @@ console.log(player.plays); // console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "iiiiiii", "aaaaaaa"])); // console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd","aaaaaaa", "iiiiiii"])); // console.log(scrabble.highestScoreFrom(["aaa", "asefr", "aer", "aserd", "aaaaaaa", "zzzzz"])); -// -// //testing score +// // +// // //testing score // console.log(scrabble.score("iiiiiid")); // console.log(scrabble.score("iiiiiii")); // console.log(scrabble.score("aaaaaaa"));