Javascript Constructors


#1

Is my code correct?

3) Add a lives property and subtractLife and addLife methods that will increment or decrement a player's lives. A new player should start off with 3 lives.

4) Create a function called GameController that takes a Player as an argument along with a guess (in this case it will be any number from 1 - 10). When your function is called it should generate a random number from 1 - 10 and give the user 10 points for every correct answer. If the guess is incorrect then the user will lose a life. When a user has zero lives left this function will log "Game Over!" to the console and reset the user's score.

Bonus: if the user gets three guesses correct in a row award them an extra life!

function PlayerConst(userName, score, highScore) {
this.username = userName;
this.score = score;
this.highScore = highScore;
this.gameOver.reset = score;

}

}

PlayerConst.prototype.update = function update(){
this.score++;
if(this.score > this.highScore){
this.highScore = this.score;
}

PlayerConst.prototype.lives = function lives(){
this.addLife = addLife++;
this.subtractLife = subtractLife--;
}

new PlayerConst.prototype.lives(3);

function GameController(guessRanNum){
guessRanNum = random (1,10);
this.guessRanNum;
this.player;

if(guessRanNum != true){
console.log("Game Over!");
return PlayerConst.gameOver.reset;
}
if(user ===3 PlayerConst.gameover.reset){
return PlayerConst.prototype.addlife;
}


#2
this.addLife = addLife++;
this.subtractLife  = subtractLife--;

these aren't methods but values. Methods would be function assigned to a property.

Also this makes no sense:

new PlayerConst.prototype.lives(3);

PlayerConst is a constructor that can be used with new to construct a PlayerConst object. But PlayerConst.prototype.lives is not a constructor but a method added to the constructor also this method takes no parameters so what should the 3 do? Maybe just add a lives property inside of the PlayerConst constructor?

guessRanNum = random (1,10);

random numbers can be generated by Math.random(). Then they will be in the range from 0 (included) to 1 (excluded). For other ranges just add or multiply numbers to this range until it fits.

PS: I guess here:

if(user ===3 PlayerConst.gameover.reset){

something went missing.