# Number Guesser - JavaScript project

Hello there,
I am stuck in task number 4. The task says following:

Create a `compareGuesses()` function. This function will be called each round to determine which guess is closest to the target number.

This function:

• Has three parameters representing the user (human) guess, a computer guess, and the secret target number to be guessed.
• Determines which player (human or computer) wins based on which guess is closest to the target. If both players are tied, the human user should win.
• Return `true` if the human player wins, and `false` if the computer player wins.

I have already created below function as per the above mentioned task and when I wanted to test it out, I called it with example values and it looks like my function is wrong, I guess, I made an error in the logic, can someone kindly assist me please? So I can get the correct code and move on to the next task in the project.

``````const compareGuesses = (humanGuess, computerGuess, targetNumber)=>{
if (Math.abs(humanGuess - computerGuess) === Math.abs(computerGuess - humanGuess)){
return true;
}else if (Math.abs(humanGuess - targetNumber) > Math.abs(computerGuess - targetNumber)){
return true;
}else{
return false
};
}
compareGuesses(5,8,5);
``````

If you have a result in the form of a boolean and you want a boolean, then rather than testing whether the boolean is true and then returning true / otherwise false… return the boolean that you already had.

There are two cases, player1 wins, player2 wins. You have three branches in your if-statement.

If you’re testing which is closer then that would be talking about two distances, but you’re doing the whole `abs(a - b)` thing four times and they’re all different. If there are two things that you should be considering but you have four, then what are the other two?

You’re missing two semi-colons. It’s easier to skip all of them than to remember to put them in each place they belong.
If they don’t do anything then you may as well not write them out.

Have you already done this “Guessing a number” project? I would like to know whether my code for the task 4 is correct or incorrect.

Sadly there is no solution of it,hence I posted it.

I’m pointing out an issue with the logic here