SyntaxStudy
Sign Up

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

Test Cases

1
Input: factorial(5)
Expected: 120
2
Input: factorial(0)
Expected: 1
3
Input: factorial(3)
Expected: 6
4
Input: factorial(1)
Expected: 1
Your Solution