Program to find factorial of given number using JavaScript. (12)

 <html>
<head>
</head>
<body>
Enter a number: <input id = "num">
<button onclick = "fact()"> Factorial </button>
<p id = "res"></p>
<script>
function fact(){
var i, num, f;
f = 1;
num = document.getElementById("num").value;
for(i = 1; i <= num; i++)  
{
f = f * i;
}
i = i - 1;  
document.getElementById("res").innerHTML = "The factorial of the number " + f ;
}
</script>
</body>
</html>

Comments

Popular posts from this blog

Question Collection-11

Important Questions for XII