JavaScript removeEventListener — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript removeEventListener 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
Remove a listener
easy10 minAttach then remove a handler, so clicking leaves the text alone.
- 2
Store the handler first
easy10 minKeep the handler in a variable so it can be removed.
- 3
Remove from inside the handler
easy10 minMake the handler take itself off so it only ever runs once.
- 4
Use once instead
easy10 minAchieve the same single run with the once option.
- 5
Stop counting on demand
medium10 minThe stop button should remove the counting handler.
Find the bug(5)
- 1
Fix the anonymous handler removal
easy8 minTwo identical-looking functions are still two different functions.
- 2
Fix the handler removed with brackets
easy8 minremoveEventListener needs the function, not its result.
- 3
Fix the mismatched capturing flag
easy8 minA capturing listener must be removed with capturing too.
- 4
Fix the wrong event name removed
easy8 minThe name must match the one it was added with.
- 5
Fix the counter that never stops
easy8 minThe stop button is not removing the counting handler.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace