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
Use the below code:
function isOdd(num) { return num % 2;} console.log("1 is " + isOdd(1)); console.log("2 is " + isOdd(2)); console.log("3 is " + isOdd(3)); console.log("4 is " + isOdd(4));
1 represents an odd number, while 0 represents an even number.