Why won`t my code work? (SyntaxError: Unexpected identifier)


#1

function getUserChoice() {
  var userName = prompt("Rock, Paper or Scissors?");
 userInput = userInput.toLowerCase(); 
  if (userInput === "rock" || userInput === "paper" || userInput === "scissor" ) {
      return userInput;
    } else {
      console.log("Error!");
      }
}

function getCumputerChoice() Math.floor(Math.random() * 3)

switch (randomNumber) {
  case 0: 
    return "rock";
  case 1:
    return "paper";
  case 2:
    return "scissor";
    }

function determineWinner() {

  
  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!";
    }
  }
}

function playGame() {
  var userChoice = getUserChoice();
  var computerChoice = getComputerChoice();
  console.log("You threw: " + userChoice);
  console.log("The computer threw: " + computerChoice);
  console.log(determineWinner(userChoice, computerChoice));
}


playGame();

#2

Check all your functions. Make sure they are all following the correct syntax(remember the that for every opening brace there must be a matching closing brace).
Also check your switch statement to ensure their is a default case


#3

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