Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

Conditional Statements - Part 2


JavaScript program to find the given number is even or odd

Note: any number divisible by 2 is even number
Steps: Take the given number divide it by 2, if we get the remainder 0 then the given number is even number, else given number is odd

Using if else statement:
var num = 15;
if(num%2 == 0)
document.write(num," is even");
document.write(num," is odd");

Using conditional operator:
var num = 4;
var result = (num%2==0) ? " is even" : " is odd";

Interview Questions: