JannieT JannieT - 6 months ago 10
Javascript Question

How to determine if a number is odd in JavaScript

Can anyone point me to some code to determine if a number in JavaScript is even or odd?

Answer
function isOdd(num) { return num % 2;}
console.log("1 is odd " + isOdd(1) == true);
console.log("2 is odd " + isOdd(2) == false);
console.log("3 is odd " + isOdd(3) == true);
console.log("4 is odd " + isOdd(4) == false);