Rock Paper Scissors error help

https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-i/modules/fecp-learn-javascript-syntax-functions/projects/rock-paper-scissors-javascript

I cannot FIND this error? Appreciate any help!

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:51
});
^
SyntaxError: Unexpected token )
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if(userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’) {
return userInput;
} else {
console.log(‘Error!’);
}
}

const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
}
};

const determineWinner = (userChoice, computerChoice) => {
if(userChoice === computerChoice) {
return ‘The game is 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!’;
}
}

console.log(determineWinner(‘paper’, ‘scissors’));
console.log(determineWinner(‘paper’, ‘paper’));
console.log(determineWinner(‘paper’, ‘rock’));

Hello, and welcome to the forums!

You haven’t ended your determineWinner() function so it’s throwing it off.

You may have removed a } because of the syntax highlighting after it looking like you made a mistake, but it’s an example of an arrow function making the syntax highlighting a little wonky in the learning environment sometimes. Add back the } to end the function and you should be good.

1 Like

Is there a good best-practice or tool devs use for “proofing” code? That error message wasn’t super helpful.

When you’re developing in environments that you have more control over, you can use tools like ESLint with your preferred editor that will give more “proofing” options. There’s also a section in the JavaScript course that includes more debugging topics to help you get used to the messages, along with techniques like commenting out blocks of code, adding logging, etc.

You’re right, sometimes the messages aren’t super helpful. In this case, I knew the statement it did complain about was fine, so I started looking at the lines before it

2 Likes