Write a JavaScript program to calculate factorial of n numbers
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Practical-13</title>
</head>
<body>
<script>
//Write a program to calculate factorial of n (Note: Use prompt box to get input from the user.)
var num = prompt("Enter the Number");
var fact = 1;
for (let i = 1; i <= num; i++) {
fact = fact * i;
}
alert("Factorial of the number is : " + fact);
</script>
</body>
</html>
Output:
Comments
Post a Comment