const getUserChoice = userInput =>{
userInput = userInput.toLowerCase();
If(userInput === 'rock' ||userInput === 'paper' || userInput ==='scissors')
{return userInput; }
else{console.log('Invalid select rock, paper, scissor'); }
};
why do i get this error from the above code:
SyntaxError: Unexpected token else
Your if
in the if-statement is capitalized. This will mean it won’t interpret it as an if-statement, and consequently it doesn’t take in else
(since there is no if
yet in the compiler’s view).
Rule of thumb for unexpected token errors:
Check the few lines of codes before the error happens for the error.
Unexpected token means that the token
you wrote is not expected. Often times, this is not because it’s not valid, but because some other token before-hand wasn’t closed or used properly.