Hi!
I’ve just completed the Number guesser exercise, and I’m not sure why it won’t run.
I wrote this:
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
function generateTarget ()
{
return Math.floor(Math.random() * 10);
}
function compareGuesses (humanGuess, computerGuess, targetGuess)
{
if (math.abs(targetGuess - humanGuess))
< (math.abs(targetGuess - computerGuess))
{return true}
else
{return false}
}
function updateScore (winner) {
if (winner === 'human')
{humanScore++}
else if (winner === 'computer')
{computerScore++};
}
function advanceRound(){
return currentRoundNumber++;
}
I checked the solution and the second function was defined like this:
const compareGuesses = (humanGuess, computerGuess, targetGuess) => {
const humanDifference = Math.abs(targetGuess - humanGuess)
const computerDifference = Math.abs(targetGuess - computerGuess)
return humanDifference <= computerDifference;
}
And if I replace mine with this one, it runs.
What did I do wrong in that function?
Thanks in advance!