3. computerchoice error


#1

I'm getting the same error, and my code is almost identical. Here it is:

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";
}
if (choice2 === "paper") {
    return "scissors wins";
}
}
}

Thanks!


3: computerChoice error
#2

The 2nd if statement should not be there. It should just be an else statement like in your prior else if statements.


#3

I tried what you said. Even though it shows the right thing in the white box, it keeps giving me this error:

Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!

I don't know why because the "M" is capitalized in my original code.


#4

You have far too much code in your exercise, your if/else if/else statements will overwrite computerChoice, which means computerChoice will no longer hold a random number. remove/comment out everything after this line:

var computerChoice = Math.random();

#5


#6

Nevermind. Right after I posted that screenshot I figured it out. Thank you both for all of your help!


#7