Help w What if choice 1 is paper?


#1

Please help, I am mostly needing help w the bottom half, receiving error that there is a problem w syntax, unexpected token else.

THANKS!

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

}


#2

Im still learning and im also stuck on this bit so i am no expert but if i'm correct your top else if statement needs a curly opening brack {.

Also a semi colon to finish it all off after last curly brack };


#3

Thanks, I tried but still have error message...


#4

I just figured out what was wrong with mine so i have the right code for you to compare yours too

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


#5

Omg, that worked, thanks! Not totally understanding why I needed three curly brackets to close that up, ugh...


#6

Yeah it is confusing, as i said i'm in the same boat as you, i understand the last one with the semi-colon is to close the entire function, the rest sort of become a blur lol


#7

All brackets, parentheses and curly braces (at least all of which I can think of atm) come in pairs and often wrap around something. So if there are 3 closing ones that are also 3 opening ones elsewhere.


#8

Thank You sooo much! It really worked!