8. What if choice1 is scissors? HELP MEE! PLEASE!


#1


What's wrong?? I watched 1000 time and I can't find something! The error is: SyntaxError: Unexpected token else


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 if (choice1 === "rock") {
        if (choice2 === "paper") {
        return "paper wins"; 
        }
        else {
            return "scissors wins";
        }
    }
    }
    compare(userChoice, computerChoice);


#2

okay, so your compare function first checks if the result a tie, that is fine. else if choice1 is rock, else if choice1 is paper, else if choice1 is rock. Wait what? rock again? shouldn't this be scissors? And this else if condition is also outside the function, make sure all conditions for comparison are in the compare function.


#3

In your second 'else if', you missed else{return "scissors wins";} and in your third 'else if', why choice1 is rock again? it should be scissors.


#4

thank you!! You helped me!


#5

Thanks!! But stetim was more helpful thx.


#6