What's wrong? 'What if choice1 is rock?'


#1



Hi, I am stuck on the Javascript, Build 'Rock, Paper, Scissors', lesson 6-'What if choice1 is rock?'


My code states 'Oops, try again. There was a problem with your syntax.'


function compare(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

You're missing a closing curly brace. There are a lot of text editors that will help you keep track of them by visually showing you the matching pairs when you mouse over them. But for simplicity, I've counted them as a running total here (open curly brace = +1; closing curly brace = -1)...

function compare(choice1, choice2) { ***+1
if(choice1 === choice2) { ***+2
return "The result is a tie";
} ***+1

else if(choice1 === "rock") { ***+2

if (choice2 === "scissors") {                ***+3
    return "rock wins";
}                                                           ***+2
else {                                                   ***+3
    return "paper wins";
}                                                          ***+2

}; ***+1


#3

Thankyou so much for the reply, I added a closing bracket after the closing bracket for the else statement-I needed to close the else if statement:

function compare(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";
}

};

};