Please Help Me Fix My Code!

Hello.

I received error and I can’t find it! Below is the message as well as my code. Thanks.

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:69
});
^
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' || userInput === 'bomb') {
return userInput 
} else {
  console.log('Error');
 }
};

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

function determineWinner (userChoice,computerChoice) {
  if ( userChoice === computerChoice) {
return 'Game Tied';
  } ;
if ( userChoice === 'rock') {
  if(computerChoice === 'paper') {
    return 'Computer Wins'
  } else {
    return'You Win !'
  };
};

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

 if(userChoice === 'scissors') {
   if(computerChoice === 'rock') {
     return 'Computer Wins'
   } else {
     return 'You Win !'
   };
 };
   if(userChoice === 'bomb') {
     if(computerChoice === 'bomb') {
      return 'Computer Loses!'
     } else {             
       return 'You Win!'
};
 };
   

const playGame = () => {
  const userChoice = getUserChoice('bomb');
  const computerChoice = getComputerChoice();
  console.log('You chose:'+ userChoice);
  console.log('The computer chose:' + computerChoice);
console.log(determineWinner(userChoice,computerChoice));

};
playGame();


You have an unexpected token error on line 69 (particularly on a closing parenthesis). That means that before line 69, there was some bracket/parenthesis or expression that wasn’t closed properly.

I’d just revise your code and clean up indentation to make sure everything matches. I personally prefer 4-space indents (though 3-space ones also work) as they’re easy for me personally to distinguish over 2 spaces.

1 Like

Ah, I see! Thank you so much.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.