JavaScript Code

Even or Odd Number Program

Problem Statement

given a number, write a JavaScript program with a function that takes the number as argument, and prints if the given number is even or odd


an even number leaves a remainder of 0 when divided by 2, and the odd number leaves a reminder of 1 when divided by 2

we can use arithmetic modulus operator to find the remainder of the division of given number by 2


1. check if value in num is even or odd number using if-else statement

var num = 10;

if (num % 2 == 0) {
    console.log('even number');
} else {
    console.log('odd number');