Rock, Paper, or Scissors help SyntaxError: Unexpected token )

I’ve almost completed the exercise using if/else statements but I keep getting a syntax error and cannot find the bracket it is talking about! Please can you give some advice how to proceed. See code below.

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’) {
return userInput;
} else {
console.log(“This is incorrect”);
}
};
// console.log(getUserChoice(‘pp’));
const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3);
if (randomNumber === 0) {
return ‘rock’
} else if (randomNumber === 1) {
return ‘paper’
} else
return ‘scissors’
}
// console.log(getComputerChoice());
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return ‘game is a tie’
}
if (userChoice === ‘rock’) {
if (computerChoice === ‘paper’) {
return ‘computer wins’
} else {
return ‘user wins’
}
}
if (userChoice === ‘paper’) {
if (computerChoice === ‘scissors’) {
return ‘computer wins’
} else {
return ‘user wins’
}
}
if (userChoice === ‘scissors’) {
if (computerChoice === ‘rock’) {
return ‘computer wins’
} else {
return ‘user wins’
}
}
console.log(determineWinner(‘paper’, ‘scissors’));

Hi there. Welcome to the forums.

In future, please make sure to correctly format your code. It makes it easier for us to read, and easier for us to copy it elsewhere to re-create your error. All you need to do is look for the </> icon in the menu bar which appears at the top of the text box while you type.

capture

Press Enter to go to a blank line, click that icon, and you will see this:

capture_r

Just copy and paste your code directly from the editor into that highlighted portion, and the forum will keep it formatted the way you wrote it.

I don’t get the same error as you when I put your code into my editor. Instead, I get an error that there’s a missing }

A post was split to a new topic: Rock, Paper, Scissors Syntax Error

You’re missing a } here:

return ‘scissors’
}
// console.log(getComputerChoice());

You need one more }:

return ‘scissors’
}
};
// console.log(getComputerChoice());
1 Like