7/9 Syntax Error please help!


#1

I've been trying now for two days to get past this step, and I cannot because I always end up with a stupid Syntax Error! Here's my code for this part: please tell me what's wrong!

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";
    } 
    if (choice1 === "paper") {
        if (choice2 === "rock") {
            return "paper wins";
        if (choice2 === "scissors") {
            return "scissors wins";
        }
    }
}

Please help me!!!


#2

Your're nesting the paper case inside the rock case as well which doesn't make sense as you can't choose rock and paper at the same time. This probably gave you can error already that's why you changed the else ifs to ifs but the key is to use them on the same level:

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";
    } 
} // closed the rock case here
   [else] if (choice1 === "paper") { // start with paper here [] are optional
        if (choice2 === "rock") {
            return "paper wins";
        if (choice2 === "scissors") {
            return "scissors wins";
        }
    }
}

#3

Thanks so much! You've been so helpful to everyone! :grinning: