Number guesser project

hello i am currently doing the number guesser game and i am getting errors in updateScore function. some help!!! :joy:

Hello! Can you please post your code? Remember to format your code correctly, according to this guide.

  let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;

// Write your code below:
const generateTarget = () =>{
  randomDigit = Math.floor(Math.random()*10);
  return randomDigit
};

const compareGuesses = (humanGuess, computerGuess, secretTarget)=>{
  secretTarget = generateTarget();
  let human = Math.abs(secretTarget - humanGuess);
  let computer = Math.abs(secretTarget - computerGuess);

  if(human === computer){
    return true;
  }else if(human < computer){
    return true;
  }else{
    return false;
  }
};

const updateScore = winner =>{
  winner = compareGuesses();
  if (winner){
    humanScore +=
  }else if (!winner) {
    computerScore += 1
  }
}

const advanceRound = ()=>{
    currentRoundNumber++
  }

In your compareGuesses function,
the line
secretTarget = generateTarget();
does not belong in the function (because this function call is handled in the other JavaScript file, game.js).

In the updateScore function,
you’re missing a 1 on the line

humanScore +=

And, the function call
winner = compareGuesses();
should not be in that function (because this function call is handled in the other JavaScript file, game.js).

Read the instructions for Step 5 again.

Step 5

Create an updateScore() function. This function will be used to correctly increase the winner’s score after each round.

This function:

  • Has a single parameter. This parameter will be a string value representing the winner.
  • Increases the score variable ( humanScore or computerScore ) by 1 depending on the winner passed in to updateScore . The string passed in will be either 'human' or 'computer' .
  • Does not need to return any value.

link to Number Guesser

1 Like

super helpful thank you