ReferenceError: userInput is not defined


#1

Here is what my code looks like.
It kicks back ReferenceError: userInput is not defined.
._.

function getUserChoice() {
var userInput = prompt('Rock, Paper, or Scissors?');

userInput.toLowerCase();

if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput;
} else {
console.log('Try another choice, buddy.');
}
}

function getComputerChoice() {
var computerInput = Math.floor(Math.random()*3);
if (computerInput === 0) {
computerInput = 'rock';
return computerInput;
} else if (computerInput === 1) {
computerInput = 'paper';
return computerInput;
} else if (computerInput === 2) {
computerInput = 'scissors';
return computerInput;
}
}

function determineWinner() {
if (userInput === computerInput) {
return 'You both suck!';
} else if (userInput === 'rock') {
if (computerInput === 'scissors') {
return 'Game Over, The User wins.';
} else if (computerInput === 'paper') {
return 'You got schooled, sucka.';
}
} else if (userInput === 'paper') {
if (computerInput === 'rock') {
return 'Game Over, The User wins.';
} else if (computerInput === 'scissors') {
return 'GET FUCKIN\' REKT!!!!!!11!!1!';
}
} else if (userInput === 'scissors') {
if (computerInput === 'paper') {
return 'Game Over, The User wins.';
} else if (computerInput === 'rock') {
return 'You got rocked, kid.';
}
} else if (userInput === 'bomb') {
console.log('BOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOM!!! (Cheater...)');
}
}

function playGame() {
var userChoice = getUserChoice();
console.log('The User selected: ' + userChoice);
var computerChoice = getComputerChoice();
console.log('Whereas I selected: ' + computerChoice);
console.log(determineWinner(userChoice, computerChoice));
}

playGame();

What am I missing here? It has to be something simple.


#2

remove the var keyword for userInput and computerInput from your getUserChoice() and getComputerChoice() function

Any variable declared within that function is only accessible from that function

To know more about it click here - Variable Scope


#3

Perfect. Thank you :3