Unexpected token else


#1

I've tried some of the other solutions that are in the forum, but they're not working. Any pointers on what I'm doing wrong here/what I missed? I've been staring at it for so long that I'm probably just missing something super obvious.

/*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"; }


#2

You write "else" in the wrong place, they should come after the nested if.

if( choice1 === choice2 ){
    return"The result is a tie";
} else if (choice1 === "rock") {    // return "paper wins"; is right now going to together with this else if
    if (choice2 ==="scissors") {    // it should go together with this if   
        return "rock wins";        
    }
} else {             
    return "paper wins"; 
} else if (choice1 === "paper") {    // return "scissors wins"; is right now going to together with this else if
    if (choice2 === "rock") {        // it should go together with this if
        return "paper wins";    
    }
} else {            
    return "scissors wins";          
}

Hope you understand what i mean, if not feel free to question more.


#3

Thank you, it worked!