Rock Paper Scissors part 7


#1


Syntax error: 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 (choice1 === "rock") {
        return "paper wins"
    }
    else {
        return "scissors wins"
}
};


#2

You do not need the else in this statement here. You just need the else at the end.


#3

Read the hint for this lesson. They give you an example of how to use correct syntax:

else if (choice1 condition){
if (choice2 condition){
return "something wins";
} else {
return "other wins";
}
}

Also, your if conditions should be comparing choice2 to something, not choice 1. The else if condition compares choice1.


#4

but the "scissors" where at a previous exercise, part 6 not part 7 which is the "paper" problem.

this indeed I think he mistakenly attribute to the exercise that is under question.


#5

I still get the error(Syntax error: unexpected toke else) what am I doing wrong


#6

found the solution replace the else if with if.


#7

The hint to the instructions shows that your if/else statements are inside the else if statements. Curly braces encapsulate the else if statement's code block. So if you have:

else if (choice1 code){ // this brace is the beginning of what will execute when the else if condition is met

if (choice2 condition){
    return code code code;
} else {
    return code code code;
}

} //closing brace for the else if codeblock

But if your solution works and is accepted :+1:


#8

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