Rock, Paper, Scissors: ReferenceError: dermineWinner is not defined


#1

I've been stuck on this for a good while, Not sure why it keeps coming up invalid. I haven't been able to run this game game, I keep getting this error, "ReferenceError: determineWinner is not defined"

Here's my code:

function getUserChoice() {
  var userInput = prompt('What\'s your choice?');
  userInput = userInput.toLowerCase();
  	if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors')
    {
      return userInput;
    } else {
      console.log('Error!');
    }
} 
function getComputerChoice(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 'The game is a tie!';
    }
    if (userChoice === 'rock') {
      if (computerChoice === 'paper') {
        return 'The computer won!';
      } else {
        return 'You win!';
      }
      if (userChoice === 'scissors') {
        if (computerChoice === 'rock') {
          return 'The computer won!';
        } else {
          return 'You win!';
        }
        if (userChoice === 'scissors') {
          if (computerChoice === 'paper') {
            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

On line 48, you have a closing curly bracket where you don't need one (delete it). On the other hand, your getComputerChoice() function doesn't have enough closing curly brackets, so add one more at the end of that function.

Something else I noticed was that in your getComputerChoice function you aren't setting 'randomNumber' equal to anything. Remove it from the parameters, and just set your 'Math.floor(Math.random)' equal to a variable (randomNumber in this case):

var randomNumber = Math.floor(Math.random() * 3);

If this solves your question, please be so kind as to mark this as the solution :slight_smile:


#3

Thank you, it solved the issue!