Having a problem passing the project


#1


https://www.codecademy.com/courses/learn-javascript/projects/rock-paper-scissors


ReferenceError: userChoice is not defined


function getUserChoice() {
  var userInput = prompt('Rock, Paper, or Scissors?');
  userInput = userInput.toLowerCase();
  var userName = prompt('What is your name?');
  if (userInput === 'rock' || userInput === 'paper' || 'scissors' ) {
  return userInput;
} else {
  console.log('Error!');
}
}
function getComputerChoice() {
Math.floor(Math.random() * 3);
  switch (randomNumber) {
  case 0:
    return 'rock';
  case 1:
    return 'paper';
  case 2:
    return 'scissors';
}
}
function determineWinner() {
 if (userChoice === computerChoice) {
  return 'The game is a tie!';
}
  if (userChoice === 'rock') {
    if (computerChoice === 'scissors')
      {
        return 'The user wins!';
      }
  }
  if (userChoice === 'paper') {
    if (computerChoice === 'scissors'|| 'rock')
      {
        return 'winner!';
      }
  }
  if (userChoice === 'scissors') {
    if (computerChoice === 'rock' || 'paper')
      {
        return 'winner!';
      }
  }
}
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

here:

console.log(determineWinner(userChoice, computerChoice));

you call the determineWinner with 2 arguments, to match the two parameters of your function:

function determineWinner()

0 parameters? the number of arguments at function call should equal the number of parameters a function has.

the reason you get undefined error is because userChoice and computerChoice have a local scope, they only exist inside the playGame function


#3

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