Skip to main content

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. 1

    Read the event type

    easy10 min

    Report the type of the event that fired.

  2. 2

    Read the target text

    easy10 min

    Report the text of the element that was clicked.

  3. 3

    Read the target id

    easy10 min

    Report the id of the element that was clicked.

  4. 4

    Read a data attribute

    easy10 min

    Report the data-action of the clicked button.

  5. 5

    Tell target from currentTarget

    medium10 min

    Listen on the box and report the id of each, separated by a slash.

Find the bug(5)

  1. 1

    Fix the missing event parameter

    easy8 min

    The handler needs to accept the event object.

  2. 2

    Fix currentTarget used for the clicked element

    easy8 min

    The element actually clicked is target, not currentTarget.

  3. 3

    Fix the event passed by the author

    easy8 min

    The browser supplies the event; it is not passed in by hand.

  4. 4

    Fix the dashed dataset read

    easy8 min

    dataset uses camel case for a dashed attribute name.

  5. 5

    Fix the target read as text

    easy8 min

    target 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