What if choice1 is paper? HELPPPP please!


#1


What if choice1 is paper? Help me what am i doing wrong??


I keep getting this error: "SyntaxError: Unexpected token else"


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


#2

if (choice2 === "scissors") // forgot a { bracket
            return "rock wins";
    }

next

else if (choice1 === "rock") {
        
        if (choice2 === "scissors") 
            return "rock wins";
    }
    else {
        return "paper wins";
    }
    // here forgot to close else if

next

else {
            "scissors wins";  // need to use return keyword
        }

#3

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

I'm still getting the "SyntaxError: Unexpected token else" error with this updated code


#4

In the instructions, you are given an idea of how your else if statements should look.

Example:

else if{choice1 code){
if (choice2 code){
return "someone wins";
} else {
return "other wins";
}
}

Try to use that format to make corrections to your code.


#5

Thanks a lot man! I was really confused.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.