Q.No.3 - Write a program in Java Script to print factorial of the number on a web page.
Sol.-
<html>
<head>
<title>Factorial JS- Examcomp</title>
</head>
<body>
<h2>Find Factorial using Javscript</h2>
Enter Number : <input id="num" type="number">
<br><br>
<button onclick="fact()">Check Factorial </button>
Factorail of given number is : <span id="result"></span>
<script >
function fact() {
var a = Number(document.getElementById('num').value);
var fc= 1
if(a==0){
fc= "Please Enter number greater than 0." ;
}
else if(a<0){
fc= "Please Enter Positive number." ;
}
else {
while(a>0){
fc=fc*a
a--
}
}
document.getElementById("result").innerHTML=fc;
}
</script>
</body>
</html>
OUTPUT: