Help with Rock, Paper Scissors project

Hey all - I’ve gone through steps 1-10 on the rock paper scissors problem, I’ve copied the the video explanation exactly and still getting "/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:26
if (userChoice === ‘rock’) {
^

ReferenceError: userChoice is not defined
at Object. (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:26:6)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3"

code:

const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’) {
return userInput;
} else {
console.log(‘Error’);
}
}
const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return ‘rock’;
case 1:
return ‘paper’;
case 2:
return ‘scissors’;
}
}

const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return ‘This game is a tie’;
}
}
if (userChoice === ‘rock’) {
if (computerChoice === ‘paper’) {
return ‘Sorry, computer won!’;
} else {
return ‘Congrats! You won!’;
}
}

if (userChoice === ‘paper’) {
if (computerChoice === ‘scissors’) {
return ‘Sorry, computer won!’;
} else {
return ‘Congrats! You won!’;
}
}

if (userChoice === ‘scissors’) {
if (computerChoice === ‘rock’) {
return ‘Sorry, computer won!’;
} else {
return ‘Congrats! You won!’;
}
}

console.log(determineWinner(‘paper’, ‘rock’));

Where am I going wrong? I feel like I’m going mad…

Watch your parenthesis. userChoice is out of the scope of determineWinner

1 Like

Thanks - I had a feeling I was one short on the parenthasis - is this a ( or a { to fix?

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