All exercises

Counter factory

CoreJavaScript

Runs entirely in your browser — your code never leaves your machine.

Problem

Write makeCounter(start) which returns a function. Each call to that function increments an internal count by 1 and returns the new value. start defaults to 0, so the first call returns start + 1. Two counters must be fully independent. const next = makeCounter(); next() → 1; next() → 2 const fromTen = makeCounter(10); fromTen() → 11

Related cheat sheet
Your code
Press Run tests to check your solution.