Help on What if choice1 is rock?


#1

Can someone tell me the mistake in this 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";
    }
}

It says SyntaxError: Unexpected token else
I'd really appreciate any help given, thanks!


#2

Hey @tilly9647! Just a little mistake! You forgot to open your bracket at the beggining of your compare function here:

Hope this helped! If it didnt please reply saying so! Good Luck!


#3

In addition to this a } is missing at the end of the function.


#4

Thanks so much for the help! It works now :smile: