Rock Paper Scissors Step #7


#1

Hello, I'm a bit stuck, I can't find the error in my code. I am following the directions as per Codecademy but can't see where I am missing or have an extra bracket of some sort. The error is "SyntaxError: missing ) after condition"
Thank you

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 (choice 1=== "paper") {
         if (choice2==="rock") {
           return "paper wins";
        }  else {
              return "scissors win";
            }    
 
    }
};

#2

on this line your problem is (yoda style):

else if (choice 1=== "paper")

don't see it yet? choice1 is a variable, you can't just have a space in a variable name, that will cause a problem, which results in a error, as you noticed


#3

Thank you very much!! became code blind :smiley: :frowning


#4

Follow up question/thought.......why did the error come up as "The error is "SyntaxError: missing ) after condition" if the problem was a space issue with the variable name? I was being literal and was searching for issues with any of the brackets/braces. Also, is there a site/resource with a listing of JS errors like the above with the possible problems that would cause the error to pop up?
I like Codecademy....I went through the HTML and CSS lessons which flowed very well, I felt I learned from the lessons easily. The section on JavaScript seem less structured or something to me...less of a flow...it feels like I'm missing pertinent information as I'm doing a lesson. But perhaps its just my brain with JS.

Thanks again for your help.


#5

I think the error showed the way it did, because you have a variable, a compare operator and a number:

choice 1===

and then after this 3 things, there should be a ) but it saw a string. I think that is the reason. I have no idea if there is a list with all the errors, but after a while you know the ones you encounter most, and you get better at debugging.

But html and css is really straight forward syntax, js is a bit more difficult already. Programming isn't easy


#6

awesome! Thank you for the possible reasoning for how I had the code written was read. I did find a site with the more common error messages and what could cause them. Looking to train my eye and brain to see these things, its a help to have an idea of what may cause certain error messages.
No it isn't easy, I am enjoying the process of learning and seeing the differences between the languages.
Thanks again


#7

Just keep coding, you will catch mistakes easier. In the begin i couldn't debug, now i like to think i do okay (catching someone else his mistakes is even more difficult then your own), but i am helping on the forum for a while now


#8

Thank you for your time and help! Its greatly appreciated.