Reputation: 4383
For my little app I need to do some very simple math... But for some reason I am having trouble doing it with JavaScript.
Here is the code:
(elLeftY <= elementLeftY <= elRightY)
If one of the "questions" is false but the other one is true this little code will always output true... What I want is that only when the two "questions" are true then it equals true but if one of the two is false then it equals false.
Thanks allot in advance.
Upvotes: 0
Views: 156
Reputation: 71918
You can't do it like that in javascript. You need this instead:
(elLeftY <= elementLeftY) && (elementLeftY <= elRightY)
Here is how your current code is being evaluated:
(elLeftY <= elementLeftY <= elRightY)
((elLeftY <= elementLeftY) <= elRightY)
(true <= elRightY)
(1 <= elRightY)
true
Upvotes: 3
Reputation:
You cannot cascade equality checks in Javascript, you have to split them into two expressions.
((elLeftY <= elementLeftY) && (elementLeftY <= elRightY))
Upvotes: 2