Showing posts with label javascript programs. Show all posts
Showing posts with label javascript programs. 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

Wednesday, December 8, 2010

Javascript program to find factorial of given number

Hello everybody I want to discuss the javascript code for find factorial of given number


HTML CODE




<html>
<head>
<title>
Javascript program for find factorial of given number
</title>
<script type="text/javascript">
function fact(n)
{
var m=1;
while(n)
{
m=m*n;
n--;
}
alert("Factorial of given number :"+" "+ m);
}
</script>
</head>
<body>
<h1 align="center"><font color="green">Javascript Program for calculate factorial</font></h1>
<form name="frm1">
Enter any number :<input type="text" name="fact1"><br><br>
<input type="submit" value="calculate factorial" onclick="fact(frm1.fact1.value)">
</form>
</body>
</html>

OUTPUT