[SOLVED] Else Doesn't Work


#1

All my code is right but is says “Expected an Identifier and instead saw Else”. How can I fix this?
Level is Leave It To Cleaver with JavaScript.


#2

Never mind. I just rewrote the code and it worked. wonder if its a bug or something.


#3

Please remember to try every possible solution before posting your code and requesting help. I have renamed this topic as SOLVED.


#4

No, it was a syntax (structure) error in your code


#5

Make Sure Your Indentations match up. If not, the program will think that a variable is wrapped up in a different function than intended. For example:

var x = "10";

while(true){
  while (x < 20){
     x++;
  }
}

You can clearly tell that one while loop is in another and the variable is within the second while loop, wrapped by the parent while loop. However:

var x = "10";

while(true){
  while (x < 20){
     x++;
}
}

The system might get confused because the end bracket is in a different position, parallel to the first while loop. While it may not happen all the time, sometimes, the system will bug out, thinking that the bracket intended to close the while(x < 20) loop is actually to close the while(true) loop. Meaning in the end, there is one extra or missing bracket, thus provoking an error.