ReferenceError: getUserChoice is not defined


#1

Hi. Getting this error. Would appreciate any pointers!

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

function getComputerChoice() {
var randomNumber = Math.floor(Math.random() * 3);
  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

var userChoice = getUserChoice();

you created a function name getUserchoice() not getUserChoice();.That's why you are getting the error

ReferenceError: getUserChoice is not defined

note: Javascript is case sensitive.