Else state curly brackets causing Unknown Token error, why?!

Hello, community,
This is my first post so hopefully it’s in the right spot and hasen’t already been addressed somewhere. So i’m doing the rock, paper, scissors project in the Intro to JavaScript course and it’s all going well, the only issue is a particular else statement (I commented it out below to be able to find) has curly brackets that are throwing an Unknown Token error. As soon as I take them out the program runs fine. However i have other else statements in the program with curly brackets that don’t throw any errors. I tried googleing and looking around and i can’t seem to find any info. If anyone can shed some light it would be greatly appreciated!

const getUserChoice = userInput => { userInput = userInput.toLowerCase(); if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') { return userInput; } else { console.log('Check your spelling!'); } }; const getComputerChoice = () => { let randomNumber = Math.floor(Math.random() * 3); if(randomNumber === 0) { return 'rock'; } else if(randomNumber === 1) { return 'paper'; } /* This set of curly brackets cause an Unknown Token error! else(randomNumber === 2) { return 'scissors'; } */ }; const determineWinner = (userChoice, computerChoice) => { if(userChoice === computerChoice) { return 'It\'s a tie!'; } if(userChoice === 'rock') { if(computerChoice === 'paper') { return 'The computer won!'; } else { return 'You won!'; } } if(userChoice === 'paper') { if(computerChoice === 'scissors') { return 'The computer won!'; } else { return 'You won!'; } } if(userChoice === 'scissors') { if(computerChoice === 'rock') { return 'The computer won!'; } else { return 'You won!'; } } if(userChoice === 'bomb') { return 'Bomb beats everything!'; } }; const playGame = () => { const userChoice = getUserChoice('bomb'); const computerChoice = getComputerChoice(); console.log(userChoice); console.log(computerChoice); console.log(determineWinner(userChoice, computerChoice)); }; playGame();

That happens because when you type else you should not put anything as an argument like you do next to the if or else if.

So in order for the error not to appear you have to remove the (randomNumber === 2) that’s after else.

Of course! I knew it would be something so simple haha thank you so much!

1 Like