F How to find factorial of a number? [using javascript] | CodeTheta

How to find factorial of a number? [using javascript]


Here is another factorial program but it is written in Javascript.
Here you can see a simple javascript code which calculate the factorial of a number. Here i used factorial function which takes two parameter f which is will calculate the factorial and the n which is number which is entered by the user.
After that it will goes to a for loop to calculate the factorial number and stored the calculated value.
First portion of the programming code is simple javascript code and second portion of the code is for create a button to calculate the factorial and input console

<html>
<head>
<script type="text/javascript">
function factorial(f,n)
{
l=1;
for(i=1;i<=n;i++)
l=l*i;
f.p.value=l;
}
</script>
</head>
<body>
<form>
what number you want to factorial:<input type="text" name="t"></br>
<input type="button" value="Calculate Factorial" onClick="factorial(this.form,t.value)"></br>
Factorial of your number is:<input type="text" name="p"></br>
</form>
</body>
</html>

Output of this program is:


Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us

Post a Comment