JavaScript Events — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript 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
Handle a click
easy10 minWhen the button is clicked, put Clicked into #out.
- 2
Count the clicks
easy10 minShow how many times the button has been clicked.
- 3
Use a named handler
easy10 minDefine a named function and attach it as the click handler.
- 4
Handle two buttons
easy10 minMake each button report its own name when clicked.
- 5
Read a value on click
medium10 minWhen the button is clicked, show the value of the input.
Find the bug(5)
- 1
Fix the handler called immediately
easy8 minBrackets run the function instead of passing it to the listener.
- 2
Fix the on prefix in the event name
easy8 minaddEventListener takes click, not onclick.
- 3
Fix the listener on the wrong element
easy8 minThe listener was attached to the output instead of the button.
- 4
Fix the counter reset each time
easy8 minDeclaring the count inside the handler resets it on every click.
- 5
Fix the second onclick overwriting the first
easy8 minThe onclick property holds only one handler.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace