In this program, the user will take input through the window prompt and find even or odd numbers in javascript.
<!DOCTYPE html>
<html>
<body>
<script>
function EvenOdd()
{
var a=prompt("enter a number:");
if(a%2==0)
document.write(a+" is Even number");
else
document.write(a+" is odd number");
}
</script>
<form>
<input type="button" value="EvenOdd" onclick="EvenOdd();">
</form>
</body>
</html>
Input has taken through javascript prompt method
enter a number:12 12 is Even number
'EvenOdd'
button, EvenOdd()
function will get called.EvenOdd()
, you will take input from a user by using the window prompt method and you will store user value in a variable a
.if statement
. if the number is divisible by 2 then it will give a reminder of 0.if-statement
is true then the number is even and you will print "number is even"if-statement
is not true then the else
part will get executed and you will print, the number is odd.