JavaScript : Factorial of a Number :
Here is the code for the Factorial
of a number in JavaScript code :
<script type = "text/javascript">
var n = parseInt(window.prompt("Enter
Number To Find Its Factorial:"));
var result = fact(n);
window.alert("Factorial of the given number " +
result);
function fact(n)
{
if(n == 0)
return 1;
else
return (n*fact(n-1));
}
</script>
var n = parseInt(window.prompt("Enter Number To Find Its Factorial:"));
var result = fact(n);
window.alert("Factorial of the given number " + result);
function fact(n)
{
if(n == 0)
return 1;
else
return (n*fact(n-1));
}
Output :
Enter Number To Find Its Factorial: 3
3 ! = 6