Saturday, 14 September 2024

WRITE A JAVASCRIPT TO CHECK GIVEN NUMBER IS EVEN OR ODD


CODE :-

<html>

<head>

<title>JS-3</title>

<style type="text/css">

body{

background-color:yellow;

}

.tab{

text-transform:capitalize;

background-color:lightgrey;

}

.v2{

text-align:center;

}

.v1{

background-color:blue;

color:white;

}

</style>

<script type="text/javascript">

function check()

{

var no;

no=document.f1.no.value;

var even=["EVEN"];

var odd=["ODD"];

if(no%2==0)

{

document.f1.ans.value=even;

}

else

{

document.f1.ans.value=odd;

}

return false;

}

</script>

</head>

<body>

<center>

<form name="f1" method="post" onsubmit="return check()">

<table border="1" class="tab">

<tr class="v1">

<th colspan="2"><h5>to check even or odd number</h5></th>

</tr>

<tr>

<th>enter number:-</th>

<td><input type="text" name="no" size="5" style="border-radius:15px;"></td>

</tr>

<tr class="v2">

<td colspan="2">

<input type="submit" name="submit" value="Submit" style="border-radius:10px;background-color:lightgreen;border-color:white;">

<input type="reset" name="reset" value="Reset" style="border-radius:10px;background-color:lightgreen;border-color:white;">

</td>

</tr>

<tr>

<th>given number is:-</th>

<td><input type="text" name="ans" size="5" style="border-radius:15px;"></td>

</tr>

</table>

</form>

</center>

</body>

</html>


No comments:

Post a Comment