Skip to main content

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

    Remove a listener

    easy10 min

    Attach then remove a handler, so clicking leaves the text alone.

  2. 2

    Store the handler first

    easy10 min

    Keep the handler in a variable so it can be removed.

  3. 3

    Remove from inside the handler

    easy10 min

    Make the handler take itself off so it only ever runs once.

  4. 4

    Use once instead

    easy10 min

    Achieve the same single run with the once option.

  5. 5

    Stop counting on demand

    medium10 min

    The stop button should remove the counting handler.

Find the bug(5)

  1. 1

    Fix the anonymous handler removal

    easy8 min

    Two identical-looking functions are still two different functions.

  2. 2

    Fix the handler removed with brackets

    easy8 min

    removeEventListener needs the function, not its result.

  3. 3

    Fix the mismatched capturing flag

    easy8 min

    A capturing listener must be removed with capturing too.

  4. 4

    Fix the wrong event name removed

    easy8 min

    The name must match the one it was added with.

  5. 5

    Fix the counter that never stops

    easy8 min

    The 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