My code is getting error (rock,paper,scissors project) can anyone help me out please

This is the code i wrote…

const getUserChoice = userInput => {
  userInput = userInput.toLowerCase();
}
if (userInput === "rock" || userInput === "paper" || userInput === "scissors") {
  return userInput;
  } else {
    console.log("error");
  }

console.log(getUserChoice("rock"));

and i am getting this error…

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:4 if (userInput === “rock” || userInput === “paper” || userInput === “scissors”) { ^ ReferenceError: userInput is not defined at Object.<anonymous> (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:4:5) 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:54

why is the condition checking not nested inside the function? Given you placed if/else outside/after the function, userInput is not defined outside the function because of its local scope.

2 Likes

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