Rock, Paper, Scissors exercise

Hey! I keep getting a syntax error saying that I have an extra parenthesis somewhere but I swear I don’t and when I watched the video, my code seems to be matching the instructor’s. Hoping some extra eyes can help me out here! TIA

This is the error: SyntaxError: Unexpected token )
at createScript

And here is my code:

const getUserChoice = userInput => {
  userInput = userInput.toLowerCase();

  if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
    return userInput;
  } else {console.log('Error, please type: rock, paper, or scissors');
  }
}

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 'Tie Game';
}

if (userChoice === 'rock') {
  if (computerChoice === 'paper') {
    return "Computer Won!"; 
    } else {
      return "You Won!";
    }
}

if (userChoice === 'paper') {
  if (computerChoice === 'scissors') {
    return "Computer Won!";
  } else {
    return "You Won!";
  }
}

if (userChoice === 'scissors') {
  if (computerChoice === 'rock') {
    return "Computer Won!";
  } else {
    return "You Won!";
  }
}

Assignments need to the on the one line.

Okay thank you so much! I fixed it but I am still getting the same error.

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

The error message contains details we need to examine. Please post the error message from the console.

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:55
});
^
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)

The error is on or near line 55. That may not be the actual error, though. It could be some point above that point.

Can you post the code from line 50 to 60?

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

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 ‘Tie Game!’;
}

if (userChoice === ‘rock’) {
if (computerChoice === ‘paper’) {
return “Computer Won!”;
} else {
return “You Won!”;
}
}

if (userChoice === ‘paper’) {
if (computerChoice === ‘scissors’) {
return “Computer Won!”;
} else {
return “You Won!”;
}
}

if (userChoice === ‘scissors’) {
if (computerChoice === ‘rock’) {
return “Computer Won!”;
} else {
return “You Won!”;
}
}

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

this is my whole code and the bottom console.log’s are line 52 - 54

I cannot spot the indicated error.

Please post a link to the exercise.

Same! It’s driving me mental

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

D’oh! Finally spotted the problem… Your function is not closed.

Add a closing curly brace at line 50.

Oh my gosh. Thank you so much!

1 Like