Error SyntaxError: Unexpected token else

2

I am creating a "Stone, Paper and Scissors" Game, I am in the final moment, but my code has an error that I can not identify.

var userChoice = prompt("Voce escolhe pedra, papel ou tesoura?");
var computerChoice = Math.random(1);
if (computerChoice < 0.34) {
    computerChoice = "pedra";
} else if(computerChoice <= 0.67) {
    computerChoice = "papel";
} else {
    computerChoice = "tesoura";
} console.log("Computer: " + computerChoice);

var compare = function (choice1, choice2){
if(choice1 === choice2) {
    return "O resultado e um empate";
}

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

    if(choice2 === "tesoura") {
        return "pedra vence";
    }
    else {
        return "papel vence";
    }

}

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

    if(choice2 === "pedra")
        return "papel vence";
    }
    else {
        return "tesoura vence";
    };

else if(choice1 === "tesoura") {
    if(choice2 === "pedra")
        return "papel vence";
    };
};
    
asked by anonymous 26.06.2015 / 02:11

1 answer

5

The problem seems to be here:

…
else if(choice1 === "papel") {

    if(choice2 === "pedra")
        return "papel vence";
    }
    else {
        return "tesoura vence";
    };

else if(choice1 === "tesoura") {
…

If you pay attention, you never close else if(choice1 === "papel") { - in else if(choice1 === "pedra") { just above you put } , but not%

(The ; in }; is unnecessary, but makes no difference to your code.)

    
26.06.2015 / 02:33