Skip to content

Commit 9eb793e

Browse files
Update Factorial.js
1 parent 7333e67 commit 9eb793e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

JavaScript Interview Programs/Factorial.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11

2-
// ******************************************************** Factorial **************************************************
2+
// ****************************************************************************** Factorial *******************************************************************************
33

44
// 1. Find Factorial of a Number:
5-
// Find factorial using loop:
5+
6+
// Find factorial using For loop:
67
function factorial(n) {
78
let fact = 1;
89
for (let i = 1; i <= n; i++) {
9-
fact *= i; // fact = fact * i;
10+
fact *= i;
11+
// fact = fact * i;
1012
}
1113
return fact;
1214
}
1315
console.log("Factorial using For Loop:", factorial(5));
16+
1417
// Output:
1518
// Factorial using For Loop: 120
1619

@@ -22,5 +25,6 @@ function factorial(n) {
2225
return n * factorial(n - 1);
2326
}
2427
console.log("Factorial using Recursion:", factorial(5));
28+
2529
// Output:
2630
// Factorial using Recursion: 120

0 commit comments

Comments
 (0)