What if choice1 is rock? Unexpected end of input



SyntaxError: Unexpected end of input

I keep getting this error so I checked my code against the hint that was available but it looks the same so I'm a bit lost, any insight? Please assist and thank you in advance!

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


Cramping your code together like that makes it a lot more difficult to tell if something is missing. Consider using this style instead:

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

The error message, SyntaxError: Unexpected end of input is saying that the code ended when it was expecting something else first. See anything missing at the end?


I took your advice on changing up my format and found the issue almost immediately. I can't believe one extra curly bracket at the end kept me stuck on this part for so long! Thank you very much!


var compare=function(choice1,choice2) {
if(choice1===choice2) {
return "The result is a tie";
else if(choice1==="rock")
{ if(choice2==="scissors")
{ return "rock wins"; }
{ return "paper wins"; }
SyntaxError: missing } after function body
What the heck am I doing wrong?


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