JannieT JannieT - 2 years ago 132
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 Source
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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download