Im having trouble with task 4 on the Number Guesser Project. My compareGuesses function isn’t working properly.

I tried to find the difference between the secretTarget & computerScore and secretTarget & humanScore to calculate the values for each of the parameters (humanScore, computerScore, secretTarget).

Then wrote an if statement that returns true if the computerScore and humanScore are equal and also returns true if humanScore is less than computerScore. False for everything else.

With that being said, why is it that if the

computerScore = 9 [difference = 5]

humanScore = 1 [difference = 3]

secretTarget = 4

the computer wins??

From what I think I wrote, the difference between humanScore and secretTarget is less than the difference between the computerScore and the secretTarget… So shouldn’t the human win?

**This is my code:**

let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

// Write your code below:

const generateTarget = () => {

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

}

//TASK 4

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

secretTarget = generateTarget();

humanScore = Math.abs(secretTarget - humanScore);

computerScore = Math.abs(secretTarget - computerScore);

if (humanScore === computerScore) {

return true;

}else if (humanScore < computerScore) {

return true;

}else {

return false;

}

}

const updateScore = winner => {

//winner = “”;

if (winner === ‘human’) {

humanScore++;

}else if (winner == “computer”) {

computerScore++;

}

};

const advanceRound = () => {

currentRoundNumber++;

}