Stateful Closures
Stateful Closures
A closure can remember how many times something has happened. That state lives beside the returned function, not in the public data passed to each call.
This pattern appears in UI flows such as limited retries, one-time prompts, and guarded actions. The useful part is that the caller asks a small function instead of managing the state directly.
Your task: Complete makeUseLimiter so it receives a maximum number of allowed uses. It should return a function that returns true while a use is allowed, then false after the limit is reached.
Free with a JS Exercises account
Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.
By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.
Stateful Closures
A closure can remember how many times something has happened. That state lives beside the returned function, not in the public data passed to each call.
This pattern appears in UI flows such as limited retries, one-time prompts, and guarded actions. The useful part is that the caller asks a small function instead of managing the state directly.
Your task: Complete makeUseLimiter so it receives a maximum number of allowed uses. It should return a function that returns true while a use is allowed, then false after the limit is reached.