The Factorial Forge
EasyAcc. 95.2%
+20 XP 8
The Chain Reaction
A Factorial (denoted as $N!$) is the product of all positive integers from 1 up to $N$. For example, $5! = 5 imes 4 imes 3 imes 2 imes 1 = 120$.
The Assignment
Your function receives a parameter named target.
- Initialize a variable
resultat 1. - Use a
fororwhileloop to multiplyresultby every number from 1 totarget. - After the loop, print the final value of
result.
[!NOTE] Factorial of 0 is always 1. Your code should handle this boundary!
01EXAMPLE 1
Input
target = 5Output
120Explanation: 1 * 2 * 3 * 4 * 5 = 120
Constraints
- Use a loop, not recursion.
- Handle target = 0 correctly.
MathLoopsFundamentals
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
target5
Expected Output
120
Click RUN to test your solution