Showing posts with label html code find greatest. Show all posts
Showing posts with label html code find greatest. Show all posts

Thursday, December 9, 2010

Javascript for find greatest and smallest among three numbers

Hello I want to discuss the code for find greatest and smallest from 3 numbers using javascript.

HTML CODE



<html>
<head>
<title>
Javascript Program to find greatest and smallest from 3 numbers
<script language="javascript">
function greater()
{
var num1=parseInt(document.f1.t1.value);
var num2=parseInt(document.f1.t2.value);
var num3=parseInt(document.f1.t3.value);
if(num1>num2 && num1>num3)
{
alert(num1 +" is greatest number");
}
else if(num2>num1 && num2>num3)
{
alert(num2 +" is greatest number");
}
else
{
alert(num3 +" is greatest number");
}
}
function smaller()
{
var num1=parseInt(document.f1.t1.value);
var num2=parseInt(document.f1.t2.value);
var num3=parseInt(document.f1.t3.value);
if(num1<num2 && num1<num3)
{
alert(num1 +" is smallest number");
}
else if(num2<num1 && num2<num3)

{
alert(num2 +" is smallest number");
}
else
{
alert(num3 +" is smallest number");
}
}
</script>
</head>
<body>
<h1 align="center"><font color="red">Javascript for find greatest and smallest</font></h1>
<form name=f1>
num1: <input type="textbox" name=t1><br>
num2: <input type="textbox" name=t2><br>
num3: <input type="textbox" name=t3><br><br><br>
<input type="button" value="greatest" onclick="greater()" >
<input type="button" value="smallest" onclick="smaller()">
</form>
</body>
</html>

OUTPUT




javascript