JavaScript Debounce — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Debounce lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Build a debounce wrapper
easy10 minWrite debounce and confirm no call has run yet after several calls.
- 2
Show each call resets the timer
easy10 minConfirm nothing has been received yet after three rapid calls.
- 3
Simulate a search box
easy10 minType several characters and confirm no search ran yet.
- 4
Simulate rapid resize events
easy10 minFire many resize calls and confirm layout has not run yet.
- 5
Pass arguments through the wrapper
medium10 minConfirm the debounced function accepts arguments without error.
Find the bug(5)
- 1
Fix the timer never cleared
easy8 minWithout clearTimeout, every call schedules its own run instead of collapsing into one.
- 2
Fix the function called immediately
easy8 minThe function should be scheduled, not run right away.
- 3
Fix the timer variable shared across instances
easy8 minTwo separately created debounced functions should not share one timer — here the second call cancels the first.
- 4
Fix the arguments never forwarded
easy8 minThe wrapped function should receive what it was called with.
- 5
Fix the wrapper missing its return
easy8 mindebounce must return the wrapped function for it to be usable.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace