Tuesday, February 3, 2015

Check Odd/Even Numbers JavaScript Program (for beginners)

<html> 
<head>
<script type="text/javascript"> 
var n = prompt("Enter a number to find odd or even", "Type your number here");
n = parseInt(n);
if (isNaN(n))
{
alert("Please Enter a Number");
}
else if (n == 0)
{
alert("The number is zero");
}
else if (n%2)
{
alert("The number is odd");
}
else
{
alert("The number is even");
}
</script> 
</head>
<body>
</body> 
</html>

No comments:

Post a Comment