Struggling for correct syntax

Hi all,

I’m struggling for the correct syntax in my function here. Visual Studio Code gives me “unexpected token ‘else’” and greys out the second result.

const compareGuesses = (userGuess, computerGuess, secretTarget) => {
		if (Math.abs(userGuess - secretTarget) <= Math.abs(computerGuess - secretTarget)); {
			return winner = 'human' 
		} else if (Math.abs(userGuess - secretTarget) >= Math.abs(computerGuess - secretTarget)); {
			return winner = 'computer'
		} 
};		

Please could someone point out where I’m going wrong? I can’t see it.

Found it:

const compareGuesses = (userGuess, computerGuess, secretTarget) => {
		if (Math.abs(userGuess - secretTarget) <= Math.abs(computerGuess - secretTarget)) {
			return winner = 'human' 
		} else if (Math.abs(userGuess - secretTarget) >= Math.abs(computerGuess - secretTarget)) {
			return winner = 'computer'
		} 
};		

I guess this gets easier as you get used to things!

1 Like

So your issue was that you were adding ; to the end of your conditional statements, before the opening bracket { right?

Sometimes it helps thinking about a problem out loud. You start explaining it to someone and bam, you see your own mistake

1 Like