lundi 28 décembre 2015

syntax error "SyntaxError: Unexpected keyword 'else'" for JS

Hello I'm learning JavaScript currently at Codecademy and I am up to the paper scissors rock game, though I am getting an error

SyntaxError: Unexpected keyword 'else' 

here is my code, thnx! :)

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");
    }
}

Aucun commentaire:

Enregistrer un commentaire