Practice ยท 1 of 3
Private Counter Factory
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.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Closures โ Practice