Help 'ERROR' | What if choice1 is paper?


#1


I'm getting this error : SyntaxError: Unexpected token else. What did I do wrong ?


#2

Which lesson name is this? or include the link for me. :slight_smile:


#3

ok :stuck_out_tongue_winking_eye: https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#


#4

You didn't use open and closing brackets for the if statement on line 16/17


#5

That's not the problem , It said it was right in the previous exercise


#6

I don't know. Your spacing is not great, but all of your braces seem to be in place.


#7

Yeah like before I get confused with c# and I write the curly brackets like I do in c# :stuck_out_tongue_winking_eye: but do you think it is a glitch ?


#8

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

Try using this, I cleaned up yours.


#9

It works thanks , so my problem is spacing , but in engines like visual studios would this spacing make a difference ?


#10

In python, spacing is HUGE, but in Java, and JavaScript, it mostly isn't. The problem was probably just something like a bracket, but keeping it clean is how to avoid syntax errors.


#11

Yeah , it's just that c# mixes me up with this syntax ;(


#12

Yeah I agree Thanks for your time :slight_smile:


#13

It's okay! I know that happens, it's hard to get used to a new language, keep it up, you're doing good. No problem, glad to help. :slight_smile:

I help you out because of I have time, and I'm not better than anybody else. I just want to represent the community by helping you. If it's something I can help with, I want to. :slight_smile: I appreciate your patience, and it's super cool that you program in C#, I haven't touched it. Have a wonderful day!


#14

Thanks I appreciate it ;p


#15

Thanks so much for wasting your time on my stupid mistake :wink: Yeah c# is confusing if you learn JavaScript too . Have a good day :wink:


#16

I hope I don't bug you again :wink:


#17

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