Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Olivia's JS-Scrabble #17

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 113 additions & 3 deletions scrabble.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,118 @@
var Scrabble = function() {};

// YOUR CODE HERE
Scrabble.prototype.helloWorld = function() {
return 'hello world!';
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

};

//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
ScrabbleGame.prototype.score = function(word) {
var points = 0;
for (var i = 0; i < word.length; i++) {
points += pointValue[word[i]];
}
if (word.length > 6)

Choose a reason for hiding this comment

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

The end of this function should probably go from:

if (word.length > 6)
var wordscore = word.score + 50;
 };
 return wordscore;
 }

To:

  if (word.length > 6)
    points  += 50;
  return points;
};

var wordscore = word.score + 50;
};
return wordscore;
}

ScrabbleGame.prototype.highestScoreFrom = function(wordsPlayed) {
var highestScoringWord = ""
var highestWordScore = 0
for (var i = 0; i < wordsPlayed.length; i++) {
if(score(wordsPlayed[i]) > highestWordScore) {
highestWordScore = score(wordsPlayed[i])
highestScoringWord = wordsPlayed[i]
}
}
return highestScoringWord
}

var playscrabble = new ScrabbleGame();
playscrabble.score(word)

// Scrabble.prototype.helloWorld = function() {
// return 'hello world!';
// };

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]);

Choose a reason for hiding this comment

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

Should this be totalScore += playScrabble.score(word);

}
return totalScore;
};
}

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++) {

Choose a reason for hiding this comment

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

You can call highestScoringWord and use Scrabble.score in this method instead of the loop.

if(score(wordsPlayed[i]) > highestWordScore) {
highestWordScore = score(wordsPlayed[i])
}
};