JavaScript program to print factorial of given number

Views: 125   

Following program shows you how to print factorial of given number.
In this program we get input from user and prints factorial of that number using for loop

var input = parseInt(prompt("Please enter a number:"));
var result = 1;
for (var i = 1; i <= input; i++) {
result = result * i;
}
console.log(input + " factorial is: " + result);
`

Output:

Please enter a number:
5
5 factorial is: 120
On By