0
b[1] ==b[9]
true
b[1] ==b[5]
true
b[5] == b[9]
true
b[1]==b[5]==b[9]
false

Javascript got me crazy. Does anyone have solution to it. I was making tic tac toe and checking whether rows of a board are equal. Even if they are equal it shows false.

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57

1 Answers1

3

Unlike Python, but like most programming languages, the == operator doesn't chain (except with booleans), so saying b[1]==b[5]==b[9], assuming that b[1]==b[5] is true, is equal to saying true==b[9], which doesn't make sense.

You need to use the && operator (which is the same as Python's and operator):

b[1] ==b[9]
true
b[1] ==b[5]
true
b[5] == b[9]
true
b[1]==b[5] && b[5]==b[9]
true
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34