Hello guys please help out i think i don't know how to update the score and it's really giving tough time i appreciate

let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

// Write your code below:

//secret random number created//

const generateTarget = () => {

   return  Math.floor(Math.random() * 10);

};

//compare and secret number created//

const compareGuesses = (humanScore, computerScore=generateTarget(), secretTarget=generateTarget()) => {

  //getting a winner//

  if(Math.abs(humanScore - secretTarget) <= Math.abs(computerScore - secretTarget)){

return true; }

else {

  return false;} 

};

function updateScore(){  

  compareGuesses()

}

function advanceRound() {

 if(currentRoundNumber){

   return currentRoundNumber++;

 }

};

Nowhere in your code do you increment humanScore or computerScore. You only return true and false (for human win and computer win respectively). In your updateScore() function, you need to use the value of the compareGuesses() call to determine which score is incremented:

function updateScore(){
  if(compareGuesses(humanScore)){
    humanScore++;
  }else{
    computerScore++;
  }
}

That said, I think you’re probably also missing variables for humanGuess and computerGuess, and are using their scores instead.


You seem to be a bit lost in the logic of the overall project. It might be helpful for you to write some pseudo-code first.

2 Likes