+ 1

Comparison <, > checks in js

Got this question in SL challenge and couldn't understand why the 2nd if condition returns false.. https://code.sololearn.com/W3lcXWbE3RK3/?ref=app

10th May 2019, 2:59 PM
Aravazhi
2 Respuestas
+ 3
You can't chain comparisons like that, at least not in javascript. It probably doesn't do what you think it does; here's what happens with the first one: We have a < b < c For clarity I will add parentheses (a < b) < c We evaluate `(a < b)` true < c You can't compare a bool to a number, so `true` is converted to `1`. 1 < c That happens to be `true`. And in the second case we end up with `true > a` which is `false`. Remember that challenge questions are often designed to fool you :P
10th May 2019, 3:06 PM
Schindlabua
Schindlabua - avatar
+ 1
10th May 2019, 3:17 PM
Aravazhi