8. What if choice1 is scissors?/"ReferenceError: userChoice is not defined"



When I save and submit this code it says: "oops, try again. You seem to have something wrong with your code. It threw the following error: ReferenceError: userChoice is not defined"

var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
} else if(computerChoice <= 0.67) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function (choice1, choice2){
if (choice1 === choice2) {return ("The result is a tie!");}
else if (choice1 === "rock") {if (choice2 === "scissors") {return ("rock wins");} 
else { return ("paper wins");}
else if (choice1 === "paper") {if (choice2 === "rock") {return ("paper wins");}
else { return ("scissors wins");}}
else if (choice1 === "scissors") {if (choice2 === "paper") {return ("scissors wins");}
else {return ("rock wins");}}
compare(userChoice, computerChoice);

Edit: everything is right until this part (but I don't know how to do the comparing, the last part):

else {return ("rock wins");}}


Well userChoice is not defined :slightly_smiling:
You somehow forgot the:

var userChoice = prompt("...");

that should normally be the first line. Probably got lost by removing the /**/.


Ok, now the function works :slightly_smiling: