Write a JavaScript program to find factorial of a number.
CODING:
<!doctype html>
<html>
<head>
<script>
function show(){
var i, no, fact;
fact=1;
no=document.getElementById("num").value;
for(i=1; i<=no; ++i)
{
fact= fact*i;
}
document.getElementById("answer").value= fact;
}
</script>
</head>
<body>
Enter Num: <input type="text" id="num"><br><br>
<input type="button" value="Factorial" onclick="show()">
<input type="text" id="answer">
</body>
</html
CODING:
<!doctype html>
<html>
<head>
<script>
function show(){
var i, no, fact;
fact=1;
no=document.getElementById("num").value;
for(i=1; i<=no; ++i)
{
fact= fact*i;
}
document.getElementById("answer").value= fact;
}
</script>
</head>
<body>
Enter Num: <input type="text" id="num"><br><br>
<input type="button" value="Factorial" onclick="show()">
<input type="text" id="answer">
</body>
</html
Comments
Post a Comment