What if choice1 is rock? help


#1

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

I can't see what i've got wrong in my code here! Thanks for the help!

SyntaxError: Unexpected token 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"; 
}
}


#2

Hi this part you closed the compare function earlier remove one }

if  (choice1 === choice2) {
    return "The result is a tie!"
}
}; <-- #this one

then add one } at the end for closing the compare function


#3

Pls someone help whats wrong with this i can't figure it out

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

};

#4

Hi this part

else if(choice1 === "rock") {
    if(choice2 === "scissors") { # add this one for open the if statement
        return "rock wins";
    }
    else {
         return "paper wins";
    }
} # you should add one } for closing the else if statement

the same here (you didn't open the if statement, closing the else if statement, and at the end you should close the compare function)

    else if(choice1 === "paper") {
        if(choice2 === "rock") 
            return"paper wins";
       }
       else {
           return"scissors win";
       }
    }; #just remove the semicolon
}# add this one for closing the compare function

#5

ooh thank you so much!


#6

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