5 hands-on exercises and 5 find-the-bug challenges for the JavaScript preventDefault lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Cancel the link and report that the page stayed.
Cancel the submit and report that it was handled.
Report the value of defaultPrevented after cancelling.
Stop the click reaching the box and report handled here.
Handle only the button, without stopping propagation.
It is a method and must be called.
Stopping the travel does not stop the browser navigating.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspaceThe click should not reach the box, which needs stopPropagation.
Returning false does nothing in an addEventListener handler.
Checking the target is enough, and leaves other handlers working.