7. What if choice1 is a paper? | "SyntaxError: Unexpected token else"


#1

Hi, I think I just did what was suggested here and I have no idea what is wrong, still: “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 {
return “scissors wins”;
}
}
};

Could you help me?


7. What if choice 1 is paper? - Unexpected token else
#2

Hi this part you closed the else if statement before

else if (choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins";
}
} <== remove this one

and add one after your first else statement

else if (choice1 === "rock") {
if (choice2 === "scissors") {
return "rock wins";
}

else {
return "paper wins";
}
}<== add one here 

#3

I’ve did what you’ve suggested: still SyntaxError :frowning:

else if (choice1 === “rock”) {
if (choice2 === “scissors”) {
return “rock wins”;
}
else {
return “paper wins”;
}
}

if(choice1 === “paper”) {
else if (choice2 === “rock”) {
return “paper wins”;
}
else {
return “scissors wins”;
}
}
};


#4

this part

if(choice1 === "paper") {
else if (choice2 === "rock") {
return "paper wins";
}
else {
return "scissors wins";
}
}
};

should have this strutture

else if (condition) {
    if (condition) {

   }
   else {

   }

}
}

#5

Thank you for your kindness, it’d working :confetti_ball:


#6

3 posts were split to a new topic: I checked both solutions in the forum and still cannot find the error


I checked both solutions in the forum and still cannot find the error
#7