JavaScript Custom Events — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Custom Events 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
Fire a custom event
easy10 minCreate and fire an event called itemAdded, then report it was heard.
- 2
Send data with the event
easy10 minPass a name in detail and report it.
- 3
Make it bubble
easy10 minFire the event on the inner div so the outer one hears it.
- 4
Fire on document
easy10 minFire a themeChanged event on document and report the detail.
- 5
Let two listeners respond
medium10 minAttach two listeners to one custom event and report that both ran.
Find the bug(5)
- 1
Fix the event never dispatched
easy8 minCreating an event does not fire it.
- 2
Fix the data put on the wrong property
easy8 minData travels in detail, not in a property of your own.
- 3
Fix the missing bubbles option
easy8 minA custom event does not bubble unless it is told to.
- 4
Fix the event fired on the wrong element
easy8 minThe listener is on the cart, so the event must be fired there.
- 5
Fix Event used where detail is needed
easy8 minA plain Event cannot carry a detail property.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace