9/9 Why the prompt box does not pop up?


#1

Hello there.

I "passed" the challenge for "Build 'Rock, Paper, Scissors'" Nevertheless, the output seems strange.
It gave "undefined" for userChoice. And the "prompt" box no longer pops up. I believe that my code does not work properly. Can anyone kindly point out what I did wrong? Thank you in advanced.

Here is my code:

var userChoice = prompt("Do you choose rock, paper or scissors?");
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==="rock") {
return "rock wins";
}
else {
return "scissors wins";
}
}
}

console.log(compare(userChoice, computerChoice))


#2

You'll need to close your function by adding a semi-colon to the last }. Go ahead and add one to the end of your console.log() as well.


#3

Thank you so much for your help! I did what you suggested on Chrome and it still did not give me the pop up box. I tried to copy and paste the code in safari and it worked! I guess my chrome was acting up.

Thank you again for your help!


#4

It works in my chrome console. Sometimes the browsers will cache old values and can cause problems. Try clearing the cache and restarting your browser if it happens again!


#5

Good advice! Thank you!