From cbc16c5fc313e3007b40bbdb0bf6f93948b062d2 Mon Sep 17 00:00:00 2001 From: Olivia Date: Tue, 16 May 2017 16:34:44 -0700 Subject: [PATCH 1/7] change up, no longer using prototype here after conversation with chris. added word scoring method and pointValue --- scrabble.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/scrabble.js b/scrabble.js index a7d0745..2042d14 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,5 +1,55 @@ var Scrabble = function() {}; +// YOUR CODE HERE + +var pointValue = { + '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 ScrabbleGame = function() { + this.word = word; + this.wordscore = wordscore; + this.points = points; +}; + +var score = function(word) { + var points = 0; + for (var i = 0; i < word.length; i++) { + points += pointValue[word[i]]; + } + if (word.length > 6) + wordscore = word.score + 50; +}; +return word.score; +}; + + // YOUR CODE HERE Scrabble.prototype.helloWorld = function() { return 'hello world!'; From 56f863d8e9274a802b9e5c6c2a5a65c637e60013 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 17 May 2017 14:47:33 -0700 Subject: [PATCH 2/7] Kari clears up the confusion about prototype use and constructor use. Removed properties from srabble constructor, added prototype back in, included both functions in the prototype. --- player.js | 0 scrabble.js | 33 +++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 player.js diff --git a/player.js b/player.js new file mode 100644 index 0000000..e69de29 diff --git a/scrabble.js b/scrabble.js index 2042d14..fcf6a3c 100644 --- a/scrabble.js +++ b/scrabble.js @@ -1,7 +1,5 @@ var Scrabble = function() {}; -// YOUR CODE HERE - var pointValue = { 'a': 1, 'e': 1, @@ -32,13 +30,11 @@ var pointValue = { }; +//my initializer var ScrabbleGame = function() { - this.word = word; - this.wordscore = wordscore; - this.points = points; }; - -var score = function(word) { +// setting up the structure of scoring on any word +ScrabbleGame.prototype.score = function(word) { var points = 0; for (var i = 0; i < word.length; i++) { points += pointValue[word[i]]; @@ -47,12 +43,25 @@ var score = function(word) { wordscore = word.score + 50; }; return word.score; -}; +} +var highestScoreFrom = function(wordsPlayed) { + var highestScoringWord = "" + highestWordscore = 0 + for (var i = 0; i < wordsPlayed.length; i++) { + if(score(word) > highestWordscore) { + highestWordscore = word; + highest = score(word); + } + } + return highestScoringWord +} -// YOUR CODE HERE -Scrabble.prototype.helloWorld = function() { - return 'hello world!'; -}; +var playscrabble = new ScrabbleGame(); +playscrabble.score(word) + +// Scrabble.prototype.helloWorld = function() { +// return 'hello world!'; +// }; module.exports = Scrabble; From 0bf272f0dce8fbd09b15bf3eee9e6645a8e51bc0 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 17 May 2017 15:18:04 -0700 Subject: [PATCH 3/7] beginning the player constructor function as well as the player prototype --- player.js | 3 +++ scrabble.js | 1 + 2 files changed, 4 insertions(+) diff --git a/player.js b/player.js index e69de29..8a8ef07 100644 --- a/player.js +++ b/player.js @@ -0,0 +1,3 @@ +var Scrabble = function() {}; + +//the constructor initializes and instance of of the "class", constructor is called with new Player with the addition of 'instance' vars, unlike new scrabbleGame diff --git a/scrabble.js b/scrabble.js index fcf6a3c..5277487 100644 --- a/scrabble.js +++ b/scrabble.js @@ -31,6 +31,7 @@ var pointValue = { }; //my initializer +//the constructor initializes and instance of of the "class", constructor is called with new ScrabbleGame, but without 'instance vars' var ScrabbleGame = function() { }; // setting up the structure of scoring on any word From c0a8086a83e59efe69a2b2cbe61e6472ecdd4c83 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 17 May 2017 21:21:58 -0700 Subject: [PATCH 4/7] Player methods --- player.js | 2 -- scrabble.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/player.js b/player.js index 8a8ef07..8b13789 100644 --- a/player.js +++ b/player.js @@ -1,3 +1 @@ -var Scrabble = function() {}; -//the constructor initializes and instance of of the "class", constructor is called with new Player with the addition of 'instance' vars, unlike new scrabbleGame diff --git a/scrabble.js b/scrabble.js index 5277487..246d0dc 100644 --- a/scrabble.js +++ b/scrabble.js @@ -41,18 +41,18 @@ ScrabbleGame.prototype.score = function(word) { points += pointValue[word[i]]; } if (word.length > 6) - wordscore = word.score + 50; + var wordscore = word.score + 50; }; -return word.score; +return wordscore; } -var highestScoreFrom = function(wordsPlayed) { +ScrabbleGame.prototype.highestScoreFrom = function(wordsPlayed) { var highestScoringWord = "" - highestWordscore = 0 + var highestWordScore = 0 for (var i = 0; i < wordsPlayed.length; i++) { - if(score(word) > highestWordscore) { - highestWordscore = word; - highest = score(word); + if(score(wordsPlayed[i]) > highestWordScore) { + highestWordScore = score(wordsPlayed[i]) + highestScoringWord = wordsPlayed[i] } } return highestScoringWord @@ -66,3 +66,58 @@ playscrabble.score(word) // }; module.exports = Scrabble; + +//*****************************//PLAYER//************************** + +var Player = function() {}; + +//the constructor initializes and instance of of the "class", constructor is called with new Player with the addition of 'instance' vars, unlike new scrabbleGame +var Player = function(name) { + this.name = name; + this.plays = [], + this.won = false; +}; + +Player.prototype.play = function(word) { + //should add the input word to the plays array + this.plays.push(word); +}; + +Player.prototype.totalScore = function() { + //should SUM and RETURN the score of the players words + var totalScore = 0; + var playscrabble = new ScrabbleGame(); + //iterate over plays + this.plays.forEach(function(word)); + this.plays[i] += this.plays[i]; + Math.sum(this.plays[i]); + return totalScore; +}; +} + + +var sum = 0; +for( var i = 0; i < elmt.length; i++ ){ + sum += parseInt( elmt[i], 10 ); //don't forget to add the base +} + +Player.prototype.hasWon = function() { + //should check if the player has 100 or more points and returns true or false + if (this.totalScore() >= 100) + this.won = true + else { + return this.won + } +} + +Player.prototype.highestScoringWord = function() { + var playscrabble = new ScrabbleGame(); + return playscrabble.highestScoreFrom(this.plays); +} + +Player.prototype.highestWordScore = function() { + var highestWordScore = 0 + for (var i = 0; i < wordsPlayed.length; i++) { + if(score(wordsPlayed[i]) > highestWordScore) { + highestWordScore = score(wordsPlayed[i]) +} From fafbe6dd25a46e045db228b121db0f471cba4e30 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 17 May 2017 21:29:13 -0700 Subject: [PATCH 5/7] got rid of some pasta --- scrabble.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scrabble.js b/scrabble.js index 246d0dc..831d8f0 100644 --- a/scrabble.js +++ b/scrabble.js @@ -95,12 +95,6 @@ Player.prototype.totalScore = function() { }; } - -var sum = 0; -for( var i = 0; i < elmt.length; i++ ){ - sum += parseInt( elmt[i], 10 ); //don't forget to add the base -} - Player.prototype.hasWon = function() { //should check if the player has 100 or more points and returns true or false if (this.totalScore() >= 100) From e3f62377f4acb54a5d2a6a5c3a164f640316e99b Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 17 May 2017 21:31:08 -0700 Subject: [PATCH 6/7] missing brackets --- player.js | 1 - scrabble.js | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) delete mode 100644 player.js diff --git a/player.js b/player.js deleted file mode 100644 index 8b13789..0000000 --- a/player.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/scrabble.js b/scrabble.js index 831d8f0..fcd57dc 100644 --- a/scrabble.js +++ b/scrabble.js @@ -88,9 +88,10 @@ Player.prototype.totalScore = function() { var totalScore = 0; var playscrabble = new ScrabbleGame(); //iterate over plays - this.plays.forEach(function(word)); - this.plays[i] += this.plays[i]; - Math.sum(this.plays[i]); + this.plays.forEach(function(word)) { + this.plays[i] += this.plays[i]; + Math.sum(this.plays[i]); + } return totalScore; }; } @@ -115,3 +116,4 @@ Player.prototype.highestWordScore = function() { if(score(wordsPlayed[i]) > highestWordScore) { highestWordScore = score(wordsPlayed[i]) } +}; From ae1deab09aa1189447408cfc5556bb6941fe24b0 Mon Sep 17 00:00:00 2001 From: Olivia Date: Wed, 17 May 2017 21:33:55 -0700 Subject: [PATCH 7/7] tiny typo fixes --- scrabble.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scrabble.js b/scrabble.js index fcd57dc..5b7ef4e 100644 --- a/scrabble.js +++ b/scrabble.js @@ -66,7 +66,6 @@ playscrabble.score(word) // }; module.exports = Scrabble; - //*****************************//PLAYER//************************** var Player = function() {};