JavaScript Program to find Odd or Even Number

This is a preview lesson
Register or sign in to take this lesson.

Introduction

This atricle explains how to find the square number is even or odd.
Any number divisible by 2 is an even number. For example, 0,2,6,8,10
Any number which is not divisible by 2 is an odd number. For example, 1,3,5,7,9

When checking whether a number is even or odd, we divide the result by 2 and check the remainder.In the case of a remainder of 0, the number is even, otherwise it is odd number

Example

 function checkEvenOrOdd(number) {
    if (number % 2 == 0) {
      console.log("number is" + number + "even number");
    } else {
      console.log("number" + number + "odd number");
    }
  }

Here we have created the method which will check the number is even or odd even.We have used % modulus operator to get the remainder of the given number.We need to send number parameter to this function so that it will check the given number is odd or even.

Output

Find Even Number

checkEvenOrOdd(10)

//output
number 10 is even number

Find Odd Number

checkEvenOrOdd(5)

//output
number 5 is odd number