Unexplained syntax error: token


#1


Replace this line with your code. 
I'm get a syntax error regarding this code. Could someone explain?

var compare=function(userChoice, computerChoice)
       { if (userChoice===computerChoice) 
       {return "The result is a tie!";
       }
    else if (userChoice==="rock";) 
        { if(computerChoice==="scissors";)
        return "rock wins";
        }
    else 
    { return "paper wins";
    }
        {if(userChoice==="paper";) 
        else if(computerChoice === "scissors";)
        {return "scissors wins";}
        else {return "paper wins";
         }}


#2

I'd run the code through another interpreter to get a line number for the error message.
However, your formatting is really messy, it seems likely that if you clean that up you'll find the problem in the process - and that if you keep the formatting clean you'll have a better view of the code and be less likely to make mistakes.

If I just quickly run a script on it to at least partially fix the formatting, the result is:

var compare = function(userChoice, computerChoice) {
        if (userChoice === computerChoice) {
            return "The result is a tie!";
        } else if (userChoice === "rock";) {
            if (computerChoice === "scissors";)
                return "rock wins";
        } else {
            return "paper wins";
        } {
            if (userChoice === "paper";)
            else if (computerChoice === "scissors";) {
                return "scissors wins";
            } else {
                return "paper wins";
            }
        }

And some problems are indeed much more clear now.


#3

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