Having trouble debugging


#1

The computer states there is a syntax error I've looked it over a bunch and just can't find the error. Its most likely something really simple that I am just missing. Any help would be very appreciated.

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

#2

@albionsrefuge could you help


#3

Well, I compared yours with mine.. and I think I found the problem, if you mind.

After one of your if/else statements, there's two brackets. One for the else statement, and one for the compare function. Try taking the bracket for the compare function out and put it at the very bottom.


#4

Below is what your code looks like when I move things around to suit the way my brain likes to see it. If/else statements can get pretty messy. I don't think I changed any of the code, except to add a few semicolons.

This compare function works for me, without any errors. Could it be that your syntax error is in a different part of the code?

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