7/9 syntax error: unexpected token else


#1

My first else if/else/if statement worked well, but on step 7 it keeps saying a have an unexpected token else. Am i missing a bracket? Thanks so much for the 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";
            }
        }
}
    else if(choice1==="paper") {
    
    if(choice2==="rock") {
        return "paper wins";
    } 
    }
    else {
    return "scissors wins";
    };

#2

your closing the bracket before getting the other else if inside the compare function

the } in the middle is closing it


#3

sorry, I don't really understand what you mean. could you elaborate a little? Thanks so much!


#4

Try this one:

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 if (choice1 === "Paper"){
        if (choice2 === "Rock"){
            return "Paper wins!";
        }
    }
}

#5

But in that code there is no "else" statement within the "else if" statement? Is that where I went wrong originally and I don't need an else statement?


#6

yea sure .. this is your code .. where the smiley faces are is where the function is opening (thats the first smiley face :sunglasses: lol) and where the function is closing (the second smiley face :sunglasses:) the problem is the second smiley face bracket is closing before your second "else if" statement ... so that second smiley face bracket needs to go at the end of your code and dont forget a ; to close it so your function can include the second "else if" statement thats all, the rest of your code is good.


#7

Thank you so much!!!!!!!!!!!!!