Skip to main content

Practice · 1 of 3

Private Counter Factory

CHALLENGE
Difficulty: intermediate+25 XP

Write a function makeCounter() that returns an object with two methods: - increment() — adds 1 to a private count and returns the new value - value() — returns the current count without changing it The count must start at 0 and be completely inaccessible from outside — calling the factory twice must produce two independent counters.

Back to lesson: Practice: Closures — Practice