Rock, paper, scissors - HELP

Hello!
So i followed the guide + watched the HELP VIDEO but for some reason i just can’t seem to get it right!

https://www.codecademy.com/courses/introduction-to-javascript/projects/rock-paper-scissors-javascript?action=resume_content_item

Can someone help by pointing my mistake?

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

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

console.log (getComputerChoice()); // works!

const determineWinner = (userChoice , computerChoice) => {
if (userChoice === computerChoice) {
return ‘tie!’;
}
if (userChoice === ‘rock’) {
if (computerChoice === ‘paper’) {
return “computer won!”;
} else {
return “user win”;
}
}
if (userChoice === ‘paper’) {
if (conputerChoice === ‘scissors’) {
return “computer won!”;
} else {
return “user won”;
}
}
if (userChoice === ‘scissors’) => {
if (computerChoice === ‘rock’) {
return “computer won”;
} else {
return “user won”;
}
}
};

This is what i get :

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:41
if (userChoice === ‘scissors’) => {
^^
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)

if i compare the error line:

if (userChoice === ‘scissors’) => {

with other lines of your code:

if (userChoice === ‘paper’){

in the error line, i see a => all of a sudden. Which is arrow function syntax. This is an if condition, why would you use arrow function syntax here?

1 Like

I have no idea how it got there but tnx! now its perfect :slight_smile:

Just for my personal curiosity, the SyntaxError pointed this out. Why was that not enough to find the problem?