Factorial
JAVASCRIPT
Easy
+15 XP
Problem Description
Write a function `factorial(n)` that returns the factorial of a non-negative integer.
Factorial is the product of all positive integers up to n.
Example:
factorial(5) → 120 (5 × 4 × 3 × 2 × 1)
factorial(0) → 1
factorial(3) → 6
Factorial is the product of all positive integers up to n.
Example:
factorial(5) → 120 (5 × 4 × 3 × 2 × 1)
factorial(0) → 1
factorial(3) → 6
Test Cases
Input: factorial(5)
Expected: 120
Input: factorial(0)
Expected: 1
Input: factorial(3)
Expected: 6
Input: factorial(1)
Expected: 1
Your Solution