Q:

number is even or odd fucntion in javascript

function isEven(n) {
   return n % 2 == 0;
}

function isOdd(n) {
   return Math.abs(n % 2) == 1;
}
2
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));
3
function evenOrOdd(num) { //for string length take string
  if (num % 2 == 0) {//and replace numm with string.length here
    return "even";
  } else {
    return "odd";
  }
}
0
for(let count =0; count<=100;count++){
 count%2==0? console.log(`${count} is even`):console.log(`${count} is odd`);
 ;
}
1
<!DOCTYPE html>
<html>
<body>
<script>
   var num = 5;
   document.write("Number = "+num+"<br>");
   if(num % 2 == 0) {
      document.write('Number is even!');
   } else {
      document.write('Number is odd!');
   }
</script>
</body>
</html>
0

New to Communities?

Join the community