Remember JS evaluates numbers as booleans as C does, so the == 0
part in the if sentence is not needed. If you still want to use it, do it a triple equals (===
) instead.
You can better write a simple function as:
function isOdd(n) {
return n % 2;
}
isOdd(5) // returns true
isOdd(4) // returns false
Thank you for your advice