"Unexpected token else"


#1

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(choice === "rock"); {

    if(choice2 === "scissors"); {
        return "rock wins";
    };
    else ;{
        return "paper wins";
    };
};

};

What did I do wrong? It continuously says "Unexpected token else". Any suggestions?


#2

Hi you go so many ; that you should remove
the first is Here remove the one after the condition


else if(choice === "rock");

Do the same for all the other condition also before the open { of your else statement remove it


#3
if (choice1 === choice2);{
    return "The result is a tie!";
}

else if(choice === "rock") {
    
    if(choice2 === "scissors") {
        return "rock wins";
}
else {
    return "paper wins";
}

};

This good?


#4

Hi also this one

if (choice1 === choice2);  <== this

#5

As and addition to what @wizmarco said here is an explanation what happens when you use a semicolon at that place:


#6

So is this it?
if (choice1 === choice2) {
return "The result is a tie!";
}

else if(choice1 === "rock") {

    if(choice2 === "scissors) {
        return "rock wins";
    }
    else {
        return "paper wins";
    }
}

}


#7

Nvm, I figured it out! Thanks for the help mate!