Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Factorial with a Loop

A Closer Look at Functionshard

Course · Section 10: A Closer Look at Functions · Lecture 135: Default Parameters

Implement `factorialLoop(n)` returning `n!` using an iterative loop (no recursion).

Sample tests

Input: factorialLoop(5)
Output: 120
Input: factorialLoop(0)
Output: 1

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Starting the product at 0 makes everything 0; start at 1.

Learning resources

  • MDN: Functions
Visualize this concept: Execution Context and the Call Stack →
Approach & explanation (try first)

An iterative product from 2 to n computes n! without recursion.

Loading...
⌘/Ctrl + Enter

Run your code to see results.