"SyntaxError: Unexpected token }"


#1


Hi team,

First time asking for help here. Getting really confused with the brackets. How does one keep track of the open and close?

Also, "Declare a function named getUserChoice with no parameters." I've looked at other threads but nobody seems to have declared it as a function except me? Weird.

Would appreciate help. Thank you!


function getUserchoice() {
  var userInput = prompt('Selection:');
  userInput = userInput.toLowerCase();
  if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
    return userInput;
  }  else {
    console.log('Error!');
  }
  }

function getComputerChoice() {
  randomNumber = Math.floor(Math.random() * 2);
  switch (randomNumber) {
    case 0:
      return 'rock';
    case 1:
      return 'paper';
    case 2:
      return 'scissors';
                      }
}
function determineWinner(userChoice,computerChoice) {
  if (userchoice === computerChoice) {
    return '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

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