JavaScript Throttle — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Throttle 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 throttle wrapper
easy10 minWrite throttle and confirm the first call runs immediately.
- 2
Confirm the first call is immediate
easy10 minRead the value from the very first throttled call.
- 3
Drop calls during the interval
easy10 minFire a hundred rapid calls and confirm only one ran.
- 4
Simulate a scroll handler
easy10 minFire fifty scroll calls and confirm only one layout check ran.
- 5
Confirm the wrapper is a function
medium10 minReport the type of a throttled function.
Find the bug(5)
- 1
Fix throttle that never blocks later calls
easy8 minWithout the ready flag, every call runs immediately.
- 2
Fix ready never set back to false
easy8 minWithout setting ready to false, the second call also gets through.
- 3
Fix debounce used where throttle was needed
easy8 minDebounce would delay the first call; throttle should run it immediately.
- 4
Fix the arguments never forwarded
easy8 minThe wrapped function should receive its arguments.
- 5
Fix the count assumed to be zero
easy8 minThrottle always lets the first call through, unlike debounce.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace