Build "Rock, Paper, Scissors" 6/9 help!


#1



I have checked my code multiple times and I cannot seem to find what is wrong with my code!
Can someone help me find what I did wrong? Thanks.


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

I get the error => SyntaxError: 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";
    }
   
 };


#2

The above line is missing an opening curly brace {.

if (choice1 === choice2) {

#3

Thanks! I am still getting error messages but I am working to figure them out. So far I have:

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

};


#4

Just before the last brace (the one with the semi-colon that closes the function body) insert one more close brace to close the else if.


#5

Try to omit { after " if(choice2 === scissors)"
I got the same issue by the way, and I hope you find this helpful :slight_smile: ,
Good luck <3


#6

Thank you! :slight_smile:


#7

Thank you for the help!


#8

Why don't we need to have the curly brace after this if statement?


#9

It is not advisable to work without the braces in these tracks, at least not until one is comfortable with when they are or are not required.

Recommended

if (condition1) {
    if (condition2) {

    }
    else {

    }
}
else if (condition3) {

}

and so on.