7. What if choice1 is paper? SyntaxError: Invalid or unexpected token


#1


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


SyntaxError: Invalid or unexpected token
Also, unexpected "else" when I delete the semicolons after my return statements and instead add them at the end of my "else" statements


Replace this line with your code.


#2

You have an extra quote right here, so it's messing with your code. Just get rid of it and it should be fine.


#3

Lawd jesus, why HOW did I not catch this. Thank you my friend!


#4

On a second thought I have another question. Would this code down below be viable with the quotation mark after the last 2 squiggly parentheses?

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


#5

Other than that one semi-colon, it checks out.


#6

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