JavaScript project

Hello! I am new to Codecademy and code as well. Could someone help me to figure my code below out to work properly? or any advise to code better are welcome!

The error message is this(There is nothing on line 56) :

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:56
});
^
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('Please put valid choice!');
  };
};

function getComputerChoice() {
  switch(Math.floor(Math.random() * 2)) {
  case 0:
    return 'rock';
    break;
  case 1:
    return 'paper';
    break;
  case 2:
    return 'scissors';
    break;
  }
};

function determineWinner(userChoice, computerChoice) {
  if(userChoice === computerChoice) {
    return 'The match was tie!';
  } else if(userChoice === 'rock') {
    if(computerChoice === 'paper') {
      return 'Computer won!';
    } else {
      return 'You won!';
    }
  } else if(userChoice === 'scissors') {
    if(computerChoice === 'rock') {
    return 'Computer won!';
    } else {
      return 'You won!';
  }
} else if(userChoice === 'paper') {
  if(computerChoice === 'sciccors') {
    return 'Computer won!';
    } else {
      return 'You won!';
  }
} else if(userChoice === 'bomb') {
    return 'You won!'
};

const playGame = () => {
  let userChoice = getUserChoice('rock');
  console.log(`You throw ${userChoice}`);
  let computerChoice = getComputerChoice();
  console.log(`Computer throw ${computerChoice}`);

playGame();

Hi @method7797764965
Welcome to the forums!
Switch should only take a single expression, so better put the method which generates a random value in an extra variable:

const random = Math.floor(Math.random() * 2);
function getComputerChoice(random) {
  switch(random) {
...
}

and close this function.

1 Like

Thank you very much @mirja_t for the quick answers!
I collect them with your advise but they still show me the error message below which is nothing on line58 again… :roll_eyes:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:58
});

You also need to properly close the function determineWinner. Count the opening and closing curly braces. You have more opening than closing ones. A syntax error isn’t always very specific, but at least it (often) points to the line where to look.
When you get syntax errors and have difficulties spotting them, copy your code to Fiddle. You get more precise hints for syntax errors there.

Thank you @mirja_t again! It was all solved, it was hard to find these mistakes myself. Also, I will try to Use Fiddle from the next time. Thanks again!

1 Like