Hello I am new to coding, and having difficulty with the Rock,Paper,Scrissors Project under Java script functions.
I am getting the error message: /home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:26
if(userChoice === ‘rock’){
^
ReferenceError: userChoice is not defined
To my understanding the issue is line 26 or that the parameter userChoice is not defined. I am not sure how to define it in the body of the function determineWinner. I am not sure how to assign it a value.
An example of how to define it would be helpful.
Below is my code:
const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if(userInput === 'rock' || userInput === 'paper' || userInput === 'scissors'){
return userInput
} else {
return console.log('There is an 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 = function (userChoice,computerChoice) {
if(userChoice === computerChoice){
return 'The game is a tie!';
}
}
if(userChoice === 'rock'){
return 'The computer won';
if(computerChoice === 'paper'){
} else{
return 'You won';
}
}
The line referred to in the error message should be included inside your determineWinner() function.
P.S. When posting code please follow these guidelines: How do I format code in my posts?
It appears that one of our moderators formatted your code for you this time.
Hi, I am almost completed (on step 10/14) with the Rock, Paper, or Scissors Project, but I keep running into this error and I don’t know what needs fixing. Thanks, Ashley
Error:
/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:42
});
^
SyntaxError: Unexpected token )
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
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)