9+ JavaScript Odd-Even Program Examples

This post contains a total of 9+ Hand-Picked JavaScript Odd-Even Program Examples with Source Code. All the Odd-Even programs are made using JavaScript Programming Language.

You can use the source code of these programs for educational purpose with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Genes Sambayena

Made by Genes Sambayena. A simple JavaScript Odd or Even Checker. ( Source )

5
The number: 5 is ODD
<!DOCTYPE html>
<html>
<head>
   <title>Even and Odd number calculator</title>
    <style>
        body {
    background-color:#5f5f5f;
    color:#fff;
}
        </style>
</head>
<body>
<script>
    var number = prompt("Enter a number");
var isEvenOrOdd = (number % 2 == 0) ? "EVEN": "ODD";
document.write("The number: " + number + " is " + "<strong>" +isEvenOrOdd + "</strong>");
    </script>
</body>
</html>

2. By Mohammadreza

Made by Mohammadreza. Program to get all the odd and even numbers in a given range. ( Source )

<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <h1>
           <em> Even and odd numbers</em>
        </h1>
    <style>
        h1{
    color:black;
}
body{
    color:green;
}
body o{
    color:black;
}
body h{
    color:red;
}
body l{
    color:black;
}
body f{
    color:black;
}
        </style>
    </head>
    <body>
        <script>
            var q= prompt("enter a number less than 10000");
if (q>10000){
    alert("THE number you entered is more than 10000");
}
else{
    document.write("<o>"+"Even numbers :"+"<br />"+"</o>");
    for (i=0;i<=q;i++){
        if (i%2==0){
            document.write("<h>"+i+"</h>"+'\n');
        }
        else{
            continue;
        }
    }
        document.write("<br />"+"<l>"+"odd numbers :"+"<br />"+"</l>");
    for (i=0;i<=q;i++){
        if (i%2==1){
            document.write(i+'\n');
        }
        else{
            continue;
        }
    }
}
document.write("<hr />"+"<f>how wonderful this program is</f>");
            </script>
    </body>
</html>

3. By Or Shalmayev

Made by Or Shalmayev. Enter number than click check to see if its odd or even. ( Source )

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>check if even or odd</title>
  <style>
      span{
          display:inline-block;
      }
  </style>
</head>
<body>
<i style="float:right;" id="clockD"></i><br>
<i style="float:right;" id="clockT"></i>
<h1>Check if <span id="e">Even</span> or <span id="o">Odd</span></h1>
<label>Enter Your Number:<input type="text" id="nField" size="10"></label>
<input type="button" value="check" onclick="check()">
<p id="pResult">The Result is Here</p>

<script>

function check(){
  var num;
  var result;
  num = document.getElementById('nField').value;
  if(num==0){
      document.getElementById('pResult').innerHTML ="<h2>Please enter a <u style='color:red;'>valid</u> number!</h2>";
      document.getElementById('e').innerHTML ="<i style='color:black;'>Even</i>"
    document.getElementById('o').innerHTML="<i style='color:black;'>Odd</i>"
  }
else if(num%2==0){
document.getElementById('pResult').innerHTML ="<h2 style='color:blue;'>Number "+"<span style='color:green;'>"+num+"</span>"+" Is Even!</h2>"
document.getElementById('e').innerHTML ="<i style='color:blue;'>Even</i>"
    document.getElementById('o').innerHTML="<i style='color:black;'>Odd</i>"
}else{
    document.getElementById('pResult').innerHTML="<h2 style='color:purple;'>Number " + "<span style='color:red;'>"+num+"</span>"+" Is Odd!</h2>"
    document.getElementById('o').innerHTML="<i style='color:red;'>Odd</i>"
    document.getElementById('e').innerHTML ="<i style='color:black;'>Even</i>"
}
}
//clock 
function clockFunc(){
    var showTime = new Date();
    //Date
    var day = showTime.getDay();
    var dayarr = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
    day=dayarr[day];
    var date = showTime.getDate();
    var month = showTime.getMonth();
    var year = showTime.getFullYear();
    document.getElementById('clockD').innerHTML= day + " " + date + " " + month + " " + year ;
    //Time
    var h = showTime.getHours();
    var m = showTime.getMinutes();
    var s = showTime.getSeconds();
    //Adding "0" to hours minutes and seconds
    h = (h<10) ? "0" + h : h;
    m = (m<10) ?  "0" + m: m;
    s = (s<10) ? "0" + s : s;
    document.getElementById('clockT').innerHTML=h+":"+m+":"+s;
    setTimeout("clockFunc()",1000);
}
clockFunc();
</script>
</body>
</html>

4. By Amethyst Animion

Made by Amethyst Animion. Prints odd even numbers in given range. ( Source )

0 is Even
1 is Odd
2 is Even
3 is Odd
4 is Even
5 is Odd
6 is Even
7 is Odd
8 is Even
9 is Odd
10 is Even
a = prompt("Enter Max Number"); for(var i=0; i<=a; i++) document.write(i%2==0 ? i+" is Even<br>" : i+" is Odd<br>");

5. By Ahmad Bahbouh

Made by Ahmad Bahbouh. Enter number than click calculate. ( Source )

<!DOCTYPE html>
<html>
	<head>
		<title>Page Title</title>
	</head>
	<body>
		<form method="post" target="#">
		    <p>Please enter a value to find all odds and events until it</p>
		    <input type="text" value="100" id="txt_">
		    <input type="button" value="calculate" onclick=odd_vs_even()>
		</form>
        <script>
            function odd_vs_even()
{
    var x = document.getElementById('txt_').value;
    for(var i=0;i<=x;i++)
    {
        if(i %2 != 0)
            document.write(i + " is an odd number" + "<br>");
        else
            document.write(i + " is an even number"+ "<br>");
    }
}
            </script>
	</body>
</html>

6. By Farhan A Hanfee

Made by Farhan A Hanfee. Change var number to your number. ( Source )

Odd
var number = 5//put even or odd numbers
            alert((number%2==0) ? "Even" : "Odd")
           
 alert("check out my other code also thanks for viewing my code :D");

7. By Maxwell D. Dorliea

Made by Maxwell D. Dorliea. ( Source )

20
The Number You Enter Is An Even Number
<!DOCTYPE html>
<html>
    <head>
        <title>Even Or Odd</title>
    <style>
        
.copyright{
    
    background:hsl(65,100%, 60%);
    position:absolute;
    bottom:0;
    right:0;
}
        </style>
    </head>
    <body>
        <p class="copyright">Copyright &copy;Max Code</p>
        <script>
            var max=prompt("Enter A Number");


if(max%2==0){
    
    document.write("<b>The Number You Enter Is An Even Number</b>");
}

else {
    
    document.write("<b>The Number You Enter Is An Odd Number</b>");
    
}
            </script>
    </body>
</html>

8. By Sharvil Khot

Made by Sharvil Khot. A Basic Odd-Even checker using JavaScript. ( Source )

6
6 is Even
<!DOCTYPE html>
<html>
    <head>
        <title>Even or Odd</title>
    </head>
    <body>
    <script type= "text/JavaScript">
        var num1
        
             
            num1 = prompt("enter any number");
            if(num1%2==0)
            {
                document.write("<h1>");
                document.write(num1+""+" is even");
            }
            else
            {
                document.write("<h1>");
                document.write(num1+""+" is odd");
                }
    </script>
        
    </body>
</html>

9. By Jingga Sona

Made by Jingga Sona. ( Source )

<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    <style>
        body {
    background-color:green;
    text-align:center;
    position:relative;
    top:150px;
}
        </style>
    </head>
    <body>
    <h2>ODD or EVEN?</h2><h3>Input A Number!</h3>
        <button id="hello" onclick="text()">Check</button>
        <input id="apaan" type="number" placeholder="input number here...">
    <script>
        var x = '' ; function text() { x = apaan.value.toLowerCase() ;
if (x % 2 == 0) {alert("EVEN!")}
else if (x % 2 != 0) {alert("ODD!")}
else {alert("No Input!")}
}
        </script>
    </body>
</html>

10. By Kat

Made by Kat. ( Source )

10
Even
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <style>
            body {
    background-color: violet;
    font-size: 30px;
    display: grid;
    font-style: ;
}
            </style>
    </head>
    <body>
        <script>
            let number = prompt("Enter A Whole Number","0");
let result = number % 2;

function pass(text) {
	if (number === "")
     document.write(`Inavalid Input`);
	else 
     document.write(`${text} number`);
}

(result === 0) ? pass("Even") : pass("Odd");
            </script>
    </body>
</html>