Keep getting "expected expression, got keyword "else" syntax error. its getting very upsetting


#1

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

keep getting a syntax error: "expected expression, got keyword "else"


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

   if(choice2 === "scissors")    
        return "Rock wins";
    }

you forgot a { bracket

also need a } bracket for first else if after closing else


#3

Hi! You've got quite a number of missing curly braces. The first else if block house an if and an else statement. Also, watch your spellings (upper and lower cases):

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

#4

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