7. What if choice 1 is paper? SyntaxError expected expression


#1

Can't see what I am doing wrong.

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

inside your else if, you should nest a if and a else:

else if (choice1 === "rock") {
    if (choice2 === "scissors") {
        return ("rock wins") 
    }
    else {
        return ("paper wins")
    }
// missing } to close else if

you forgot the closing curly bracket of else, see comment in above code


#3

Thank you very much! Bit of a struggle to keep track of all those curly brackets.


#4

using indention helps, use four spaces, you should be able to achieve this with the tab key in the codecademy editor


#5

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