Javascript tutorial - rock, paper, scissors


#1

Hi,
I tried to follow the instruction as exactly as I could, but I always get this error message:

/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:25
if (userChoice === ‘rock’) {
^

ReferenceError: userChoice is not defined
at Object. (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/rockPaperScissors.js:25: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:542:3rd_place_medal:

My code is here: https://gist.github.com/8c3244ab77c1e28e614f2950a82c020a
What have I done wrong?
Can anybody help with this, please?

Zamek


#2

this is your determineWinner function:

const determineWinner = (userChoice, computerChoice) => {
  if (userChoice === computerChoice) {
    return 'This game is a tie';
  }
} // closes function

seems a bit short, the game can now only end in a tie.

Given the rest of the conditions/comparisons are not nested inside the function, you get a scope problem. userChoice (one of the parameter of determine winner function) has a local scope.


#3

WOW!!
Yes! You’re right!
Thanks a lot!
I was so blind…