Lesson 7 if choice1 is paper Help Please


#1

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


Syntax error


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


#2

The only way anybody can find the error in your code above is to spend time counting the brackets, something you could do on your own. If you want obvious errors to stand out, then give everything some breathing room. Write statements and closing braces on their own lines. Some style guides even recommend writing the opening brace on its own line. Scrunched up code is hard to read and debug. White space is our friend, not something to avoid.

{  count = 8

}  count = 8

The count matches so the error might be in their placement. That's one possible issue.

There is more. We cannot write an else if after an else. Clean up your code and locate the errors.


#4

The previous response's right.
When you write an "if" or "else" you must write an "{" at the beginning and at the end. On the contrary, that will cause an error.

Check your code.


#5

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