Somebody please help! I'm stuck (What if choice1 is paper)


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#

Help! I keep getting "SyntaxError:Unexpected keyword 'else'"...What am I doing wrong?? Any help will be greatly appreciated!


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


#2

Go look up the syntax for if-statements - searching for "mdn if-statement" in a search engine should get you to the right place.

There are also some formatting issues that, while they don't affect execution, can make (other) bugs more difficult to spot or you might put something in the wrong place as a result. If you're unsure how it should look then you can run it through a js beautifier (you'll find some by using a search engine)

Feel free to follow up with more questions, but that's what you should be looking at (and practising looking things up)


#3

you need to get rid of semi columns on curly brackets except for the function one at the very end
then u need to start else if statement after the end of first if statement which is if (choice 1 === choice) {
} <----- start your else if statement from here.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.