What if choice1 is rock error syntax


#1

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

I keep getting unexpected else token error


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


#2

here:

if(choice1 === choice2)

normal if conditions have curly brackets ({}) to mark the start and end of your if clause, which are missing in your case


#3

I added the bracket and took out the semicolon and the error persists


#4

can i see an updated version of the code?


#5

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

#6

your code works fine now :slight_smile: If problems persist, refresh the page or try a different browser


#7

Thanks, can you tell me what you changed?


#8

i didn't change anything, you made the changes


#9

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