Number Guesser Step 4

Hello,

I’m having issue with the code I did on Step 4 on the number guesser project. For reference, this is what I rendered:
// Step 4
const compareGuesses = (humanGuess, computerGuess, targetGuess) => {
if (Math.abs((humanGuess - targetGuess) < (computerGuess - targetGuess)) {
return true;
} else if (Math.abs((humanGuess - targetGuess) > (computerGuess - targetGuess)){
return false;
} else {
return true;
}
};

the syntax keeps telling me ‘Unexpected token’. I tried understanding Math abs but I can’t seen to grasp it. Thanks in advance

Hi @denzelsugayan6884482

Check if you have as many closing brackets / parenthesis as opening ones.

Hi mirja_t

thank you for reaching out! i did the ones you recommended, but now its telling me there’s an ‘Unexpected identifier’. Kinda like this:
if Math.abs((humanGuess - targetGuess) < (computerGuess - targetGuess) {
^^^^

Same issue here. Count how many opening parenthesis and how many closing ones.

i tried, i dont if my code block is correct, and why the syntax is acting this way. im sorry

Ok, what are you trying to check with your if statement?
Math.abs() returns a number or ‘NaN’. So in most cases the if statement evaluates to true.
Also check the syntax for an if statement. After the keyword ‘if’ you have to write parenthesis unless you’re using the ternary operator.

if( condition ) { 
// function
}

Why don’t you console.log(Math.abs((humanGuess - targetGuess) < (computerGuess - targetGuess))) to see what it evaluates to.