JavaScript Factorial Number
<html>
<head>
<title>Form using Factorial - JavaScript </title>
<script>
function fact()
{
var n = parseInt(frm1.txt1.value);
var f=1;
for(a=1;a<=n;a++)
{
f = f*a;
}
document.writeln("Factorial = " + f);
}
</script>
</head>
<form name="frm1">
Enter Number : <input type="text" name="txt1"><br>
<input type="button" name="btn1" value="Factorial" onClick="fact();">
</form>
</html>
____________________________
ODD EVEN NUMBER USING JAVA SCRIPT
<script>
function ifdemo()
{
if(frm1.txt1.value%2==0)
{
document.write("This Number Is Even");
}
else
{
document.write("This Number Is Odd");
}
}
</script>
<form name=frm1>
Number 1 : <input type=text name=txt1><br>
<input type=button name=btn1 value="Check" onClick="ifdemo();">
</form>
_____________________________
Reverse Number Printing Using JavaScript
<html>
<head>
<title> use of while loop</title>
<script languge="JavaScript">
function reverse()
{
/* Print Reverse Number */
var n = parseInt(frm1.txt1.value);
var rev=0,r;
while(n!=0)
{
r=n%10;
rev=rev*10+r;
n=Math.floor(n/10);
}
alert ("Reverse Number Is = "+rev);
}
</script>
</head>
<form name="frm1">
Enter Number : <input type="text" name="txt1"><br>
<input type="button" name="btn1" value="Reverse" onClick="reverse();">
</form>
</html>
__________________________
Addition (SUM) Using JavaScript
<html>
<head>
<title> Use of JavaScript </title>
<script language="JavaScript">
function addition()
{
a=parseInt(frm1.txt1.value);
b=parseInt(frm1.txt2.value);
c=a+b;
document.writeln ("Addition : " + c);
}
</script>
</head>
<form name=frm1>
Enter Number 1 : <input type=text name=txt1><br>
Enter Number 2 : <input type=text name=txt2><br>
<input type=button name=btn1 value="Sum" onClick="addition();">
</form>
</html>
_______________________________
Sum of Sum Using JavaScript
<html>
<head>
<title> Do While Loop </title>
<script languge="JavaScript">
function sumofdigit()
{
/* Sum Of Digit */
var n = frm1.txt1.value;
var r,sum=0;
do
{
r=n%10;
sum=sum+r;
n=Math.floor(n/10);
}
while(n!=0);
frm1.txt2.value=sum;
}
</script>
</head>
<form name="frm1">
Enter Number : <input type="text" name="txt1" onblur="sumofdigit();"><br>
Sum Of Digit : <input type="text" name="txt2"><br>
</form>
</html>
_______________________________
Swapping Values Using JavaScript
<script language="JavaScript">
function swap()
{
a=frm1.txt1.value; //10
frm1.txt1.value=frm1.txt2.value; //11
frm1.txt2.value=a; //10
}
</script>
<form name=frm1>
<input type=text name=txt1><br>
<input type=text name=txt2><br>
<input type=button value="Swap" onClick="swap();">
</form>
____________________
learn All Programming with youtube.com/avadhtutor
No comments:
Post a Comment