javascript: else if condition not working [duplicate]

In Javascript, the equal (=) operators work as follows:

  • x = y is assignation (i.e. give variable X value Y)
  • x == y is a loose equality test (i.e. is x equal to y), it’s loose because it does type coercion (changes types to try and find a match), such as if “1” == 1 (string vs number), Javascript will convert one to the other format until it finds a match or has failed to do so.
  • x === y is strict equality. (is x equal to y) WITHOUT changing primitive type.

In your example you’re assigning values, not testing equality. That’s the source of your problems.

Also, your “if” statement is not truly working, since you’re also making an assignation, not an equality test.

Leave a Comment