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.

  1. Initialize a variable result at 1.
  2. Use a for or while loop to multiply result by every number from 1 to target.
  3. After the loop, print the final value of result.

[!NOTE] Factorial of 0 is always 1. Your code should handle this boundary!

01EXAMPLE 1

Inputtarget = 5
Output120

Explanation: 1 * 2 * 3 * 4 * 5 = 120

Constraints

  • Use a loop, not recursion.
  • Handle target = 0 correctly.
MathLoopsFundamentals
JavaScript
Loading...
3 Hidden

Input Arguments

target5

Expected Output

120

Click RUN to test your solution