Show that reading an element only works once the page is ready.
Acceptance criteria
- 1.#out should show found it.
JavaScript Tutorial · JavaScript Modules
These 10 tasks go with the JavaScript Module Scripts 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: “A script becomes a module by adding type="module" to its tag.” .
1.Simulate deferred loadingexercise · easy · 10 min
Show that reading an element only works once the page is ready.
Passes when: #out should show found it.
2.Show it runs onceexercise · easy · 10 min · practice plan
Simulate a module loaded twice sharing one execution.
Passes when: #out should show 1.
3.Report the CORS requirementexercise · easy · 10 min · practice plan
Report that a cross-origin module needs a CORS-friendly response.
Passes when: #out should show needs CORS.
4.Report the file protocol limitexercise · easy · 10 min · practice plan
Report that module scripts need a real server.
Passes when: #out should show needs a server.
5.Simulate nomodule fallbackexercise · medium · 10 min · practice plan
Report which script a module-aware browser runs.
Passes when: #out should show module script.
6.Fix the element read before it existsbug fix · easy · 8 min
Reading before the page is ready gives nothing.
Passes when: #out should show found it.
7.Fix the module counted as loaded twicebug fix · easy · 8 min · practice plan
A module included twice should still only run once.
Passes when: #out should show 1.
8.Fix CORS assumed to always allowbug fix · easy · 8 min · practice plan
A cross-origin module without CORS headers should be blocked.
Passes when: #out should show needs CORS.
9.Fix file:// assumed to workbug fix · easy · 8 min · practice plan
Module scripts generally need a real server protocol.
Passes when: #out should show needs a server.
10.Fix nomodule chosen for a supporting browserbug fix · easy · 8 min · practice plan
A module-aware browser should run the module script, not the fallback.
Passes when: #out should show module script.
Between them these tasks cover type=module, Deferred loading and Single execution.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.