Number Guesser: score only going to the computer?

Hi everyone:

Working on the Number Guesser project, and I have everything working correctly…except the score adds only to the computer’s score even when the user wins. I’m guessing it’s something wrong in the “if/else” statements in the compareGuesses function, but I’m honestly not sure. This is what I have for those code segments. Any advice is welcome.

compareGuesses = function(humanGuess, computerGuess, targetNumber) {
if (humanGuess === computerGuess) {
return true;
} else if (Math.abs(humanGuess - targetNumber) > Math.abs(computerGuess - targetNumber)) {
return false;
} else if (Math.abs(humanGuess - targetNumber) < Math.abs(computerGuess - targetNumber)) {
return true;
}
else {
return ‘Error, please try again.’;
}
};

const updateScore = () => {
if (compareGuesses === true) {
return humanScore++;
} else {
return computerScore++;
}
};

Welcome to the community! First, you might want to take a look at this: How do I format code in my posts?

To your issue, look at your function updateScore and the first conditional.

if (compareGuesses === true)

You defined compareGuesses as a function that takes 3 parameters, yet here you are just comparing if the function equals true? You need to rethink this logic. When that if statement fails and goes to else, what happens? return computerScore++;, which will increment computerScore, as you said was happening. I think we are onto something here!

Your first question should be: Why are you returning that? Where is it going (or returning to). If the code you shared is all you have, then there’s no need to return. Just do computerScore++, it’s perfectly fine and it will add plus one to the variable.