Welcome to the Treehouse Community
Looking to learn something new?
What if both inputs are not numbers? is the OR-operator really enough?
Shouldnt we use: if ( (isNan(upper) OR isNAN(lower)) OR (isNan(upper) AND isNAN(lower) ))
Antti Lylander9,673 Points
One || operator is enough. If the first test is true, the second doesn't even get evaluated. It simply does not matter anymore because we already know that either of the values is not a number and we need to throw an error.
true || true -> true false || false -> false true || false -> true false || true -> true
The logical OR operator (||) returns the boolean value true if either or both operands is true and returns false otherwise. So when one value evaluates to true, the rest of the condition will be ignored, since the first condition is met. So if either are false, the condition evaluaties also to true, you see why we use the logical OR?
If NaN(first) || NaN(second) is good enough since if they are both false, the condition will also be true