What if Choice 1 is Rock? Rock paper scissors game


#1

Hello,

This is my compare function for the Rock paper scissors game. I believe my syntax is correct but I keep on getting an error message. Can anyone help?

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

I don't believe you can start and "else if" with "else if"


#3

This is when indenting your code makes all the difference..
This is your code when indented properly:

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

Can you spot the problem?
Your function is not closed with a }; ...


#4

Hi Conolyb1. I just revisited the code for this after a week away and your advice was very useful. I was missing a }; and the indention. I am now having problems with the next little bit. I think my indention is right and I closed with a }; Can you help? Screen shot of my code: