Slip 19 - A) Write a java script code to accept a number form user and display its factorial.

Solution:

<html>
<head>
<script>
function show()
{
var i, no, fact;
fact=1;
no=Number(document.getElementById("num").value);
for(i=1; i<=no; i++)
{
fact= fact*i;
}
document.getElementById("answer").value= fact;
}
</script>
</head>
<body>
Enter Num: <input id="num">
<button onclick="show()">Factorial</button>
<input id="answer">
</body>
</html>

Post a Comment

0 Comments