Java Script


JavaScript Tutorial


Admission Enquiry Form


Check odd, even using if else

Example:

<html>
<head>
<title>odd even using if else</title>
</head>

<body>
<script>
var num;
num=10;
if(num%2==0)
{
document.write("number is even");
}
else
{
document.write("number is odd");
}
</script>
</body>
</html>


Check odd, even in if else using prompt() function

Example:

<html>
<head>
<title>odd even using prompt() in if else</title>
</head>

<body>
<script>
var num;
num=parseInt("Enter a number");
if(num%2==0)
{
document.write("number is even");
}
else
{
document.write("number is odd");
}
</script>
</body>
</html>

Check odd, even in if else on Button click using function

Example:

<head>
<title>odd even using function in if else</title>

<script>
function odd_even()
{
var num;
num=parseInt(prompt("Enter a number"));
if(num%2==0)
{
document.write("number is even");
}
else
{
document.write("number is odd");
}
}//end of function
</script>
</head>
<body>
<input type="button" value="click" onClick="odd_even()">
</body>
</html>