JavaScript Event Object — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Event Object 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
Read the event type
easy10 minReport the type of the event that fired.
- 2
Read the target text
easy10 minReport the text of the element that was clicked.
- 3
Read the target id
easy10 minReport the id of the element that was clicked.
- 4
Read a data attribute
easy10 minReport the data-action of the clicked button.
- 5
Tell target from currentTarget
medium10 minListen on the box and report the id of each, separated by a slash.
Find the bug(5)
- 1
Fix the missing event parameter
easy8 minThe handler needs to accept the event object.
- 2
Fix currentTarget used for the clicked element
easy8 minThe element actually clicked is target, not currentTarget.
- 3
Fix the event passed by the author
easy8 minThe browser supplies the event; it is not passed in by hand.
- 4
Fix the dashed dataset read
easy8 mindataset uses camel case for a dashed attribute name.
- 5
Fix the target read as text
easy8 mintarget is an element, so a property must be read from it.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace