I’ve run into an issue where when I attempt to add some points to my score I get the following error:
/Users/mark/Desktop/dice-game.js:39
score = this.score + points;
^
ReferenceError: score is not defined
at Player.addToScore (/Users/mark/Desktop/dice-game.js:39:15)
at rollDice (/Users/mark/Desktop/dice-game.js:14:16)
at Object.<anonymous> (/Users/mark/Desktop/dice-game.js:50:17)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
This occurs when I attempt to call the function to add 10 points player.addToScore(10);
. The code for my player can be found below:
class Player{
constructor (name) {
this.name = name;
this.score = 0;
}
addToScore(points) {
score = this.score + points;
}
getScore() {
return this.score;
};
}