Report Ready from inside a DOMContentLoaded handler.
Acceptance criteria
- 1.#out should show Ready.
JavaScript Tutorial · JavaScript Events
These 10 tasks go with the JavaScript Page Load Events chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “DOMContentLoaded and load tell you when the page is ready to work with.” .
1.Wait for the DOMexercise · easy · 10 min
Report Ready from inside a DOMContentLoaded handler.
Passes when: #out should show Ready.
2.Wait for everythingexercise · easy · 10 min · practice plan
Report Loaded from inside a window load handler.
Passes when: #out should show Loaded.
3.Check the ready stateexercise · easy · 10 min · practice plan
Report valid state when readyState is one of the three values it can hold.
Passes when: #out should show valid state.
4.Find an element after loadingexercise · easy · 10 min · practice plan
Read the heading from inside a DOMContentLoaded handler.
Passes when: #out should show Title.
5.Run in the right orderexercise · medium · 10 min · practice plan
Report the order DOMContentLoaded and load fire in.
Passes when: #out should show dom then load.
6.Fix the value read before the handler ranbug fix · easy · 8 min
The result is read outside the handler, before the event has fired.
Passes when: #out should show Ready.
7.Fix load listened for on documentbug fix · easy · 8 min · practice plan
The load event is fired on window.
Passes when: #out should show Loaded.
8.Fix the misspelled event namebug fix · easy · 8 min · practice plan
The name is DOMContentLoaded, with that exact spelling.
Passes when: #out should show Ready.
9.Fix the readyState compared wronglybug fix · easy · 8 min · practice plan
There is no ready state; the values are loading, interactive and complete.
Passes when: #out should show valid state.
10.Fix the order recorded wronglybug fix · easy · 8 min · practice plan
DOMContentLoaded fires before load, not after it.
Passes when: #out should show dom then load.
Between them these tasks cover DOMContentLoaded, load and readyState.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.