Write a program using JavaScript code to check whether a number is odd or even in Html code example
Example 1: check if even or odd javascript
function evenOrOdd(num) { //for string length take string
if (num % 2 == 0) {//and replace numm with string.length here
return "even";
} else {
return "odd";
}
}
Example 2: how to check if a number is even or odd in javascript
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));