THAPA TECHNICAL

HOUSE OF WEB DEVELOPERS AND TECHNOLOGY.

JavaScript Program to Find whether a Number is Even or Odd with Source Code

JavaScript Program to Find whether a Number is Even or Odd with Source Code

Use modulus (%). It gives you the remainder of the two numbers you are dividing.
Here in our Program, if you mod any number x by 2, you get either 0 or 1 or -1. 0 would mean it's even. Anything else would mean it's odd. This is the simple funda.



<!DOCTYPE html>
<html>
<head>
<title></title>


</head>
<body>

<h2 style="text-align: center; color: white; background-color: #FA2B6D"> JavaScript to find Odd or Even number! </h2>

<label> Enter Number </label> <br>
<input type="number" name="" id="evenOdd" onkeyup="isCheck()">
<span id="showMssg" style="color: #342BFA;">  </span>
</br><br>

<label> Enter Number </label> <br>
<input type="number" name="" id="evenOdds" onkeyup="isChecks()">
<span id="showMssgs" style="color: #FA2B44;">  </span>

<script>

function isCheck(){
var num = document.getElementById('evenOdd').value;
// alert(num);
if((num%2) == 0){
document.getElementById('showMssg').innerHTML = "Hurray! Number "+num+"  is an even number";
}
else{
document.getElementById('showMssg').innerHTML = "Oo No! "+num+"  is not an even number";
}

if(num === ""){
document.getElementById('showMssg').innerHTML = "";
}
}

function isChecks(){
var num = document.getElementById('evenOdds').value;
// alert(num);
if((num%2) == 0){
document.getElementById('showMssgs').innerHTML = "Hurray! Number "+num+"  is an even number";
}
else{
document.getElementById('showMssgs').innerHTML = "Oo No! "+num+"  is not an even number";
}

if(num === ""){
document.getElementById('showMssgs').innerHTML = "";
}
}

</script>

</body>
</html>


You can check below here by simply enter any number to Find whether a Number is Even or Odd in JavaScript


"I need your Help" 
"Honestly, I have no idea how much to ask you for, but if you Donate minimum 30rs using PAYTM to support me, It's really gonna help me a lot." 
Payment options is PAYTM NUMBER: 9518369954


JavaScript to find Odd or Even number!







No comments:

Post a Comment