Something wrong with the syntax ( token else). how do i rearrange it to get it work?


#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";
        }
        if(choice2 === "rock"){
            return "paper wins";
        }
        else{
            return "scissors wins";
        }
        else if(choice1 !== "rock"){
                return "invalid";
            }
            else if(choice1 !== "paper"){
                return "invalid";
        }
        else if(choice1 !== "scissors"){
            return "invalid";
        }
    }


#2

Start by identifying where the syntax is incorrect and then consider how you want that part to behave and what that would look like

If we just skipped to the conclusion then you'll run into the same problem again. The real problem here lies in how to act on the error message to reach an adjustment that sets things right.

Note that your indentation does not match your braces, that is probably not very helpful when trying to reason about your code, so a good start is to fix that, to re-indent it by the braces or perhaps change the braces to match the indentation.

Keep asking if you don't know how to approach something, but you'll have to be really specific to get a straight answer from me, because I'm reluctant to do too much of the reasoning for you


#3

""SyntaxError: Unexpected token else"" that's the error message


#4

Sure. Yeah. Okay.
But that's an observation, not something that I would have a reply to.

It might seem silly but you've got to ask the right questions in order to start looking in the right places.

If you don't know what to ask, well, then that's what you'll have to start asking about, right? I have already replied to that though, you'll need to start by identifying where the invalid syntax is.


#5

That error message describes why something is invalid. It says quite a lot about what to look for, what does it say to look for?


#6

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"
}
}
else if(choice1 === "scissors"){
if(choice2 === "rock"){
return "rock wins";
}
else{
return "scissors wins"
}
}
else if(choice1 !== "rock"){
return "invalid";
}
else if(choice1 !== "paper"){
return "invalid";
}
else if(choice1 !== "scissors"){
return "invalid";
}
}

the indentation really helped me better understand the code. thanks for ur help and patience. hope i did the indentation stuff right tho???


#7

Can't tell if you don't show!


#8

i just did. It doesnt display it the way it is on my notepad++ tho
how am i going to show???


#9

Just another exercise in problem-solving isn't it. What information have you got available?

You've got google
You've got your first post in this thread
You've got an array of buttons in your editor

Each of the above has sufficient information for figuring out how to make code stay intact.


#10

There's a whole lot going on when writing code. Remembering how to do everything, knowing all there is to know, doesn't work.

Instead we need to get good at finding information and solving problems, so that even though we can't know and remember it all, we still have access to all that we need.


#11

when you say "You've got an array of buttons in your editor", what do you mean??? if its a stupid question, i apologize. Thanks.


#12

I just mean that there are a whole lot of buttons in the post editor.


#13

Have you heard the proverb that if you give someone a fish, you'll feed them for a little while, but if you teach them to fish, you'll feed them for a lifetime?

There's a huge difference between asking for help and having things done for you. As long as you're willing to learn how to do something, there usually is someone willing to help, don't let anyone just hand the fish over, that just forces you to ask again later.


#14

funny enough i was going to quote that and thank you for not giving me fish. But i didn't want to come off as...i don't even know the word for what i was thinking. THANKS FOR NOT GIVING ME FISH. LOL.


#15

I also mean that you don't need to hold back with questions!


#16