Skip to content

Commit 5fe5381

Browse files
committed
Solve firstFactorial
1 parent 6ae5776 commit 5fe5381

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/First_Factorial.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Description: For this challenge you will be determining the factorial for a
2+
// given number.
3+
4+
// Q. Have the function FirstFactorial(num) take the num parameter being passed
5+
// and return the factorial of it. For example: if num = 4, then your
6+
// program should return (4 * 3 * 2 * 1) = 24. For the test cases, the range
7+
// will be between 1 and 18 and the input will always be an integer.
8+
9+
// Examples
10+
// Input: 4
11+
// Output: 24
12+
13+
// Input: 8
14+
// Output: 40320
15+
16+
const firstFactorial = num => {
17+
let factorial = 1;
18+
19+
for (let i = 1; i <= num; i++) {
20+
factorial = factorial * i;
21+
}
22+
23+
return factorial;
24+
};
25+
26+
console.log(firstFactorial(4));

0 commit comments

Comments
 (0)