JavaScript Module Scripts — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Module Scripts 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
Simulate deferred loading
easy10 minShow that reading an element only works once the page is ready.
- 2
Show it runs once
easy10 minSimulate a module loaded twice sharing one execution.
- 3
Report the CORS requirement
easy10 minReport that a cross-origin module needs a CORS-friendly response.
- 4
Report the file protocol limit
easy10 minReport that module scripts need a real server.
- 5
Simulate nomodule fallback
medium10 minReport which script a module-aware browser runs.
Find the bug(5)
- 1
Fix the element read before it exists
easy8 minReading before the page is ready gives nothing.
- 2
Fix the module counted as loaded twice
easy8 minA module included twice should still only run once.
- 3
Fix CORS assumed to always allow
easy8 minA cross-origin module without CORS headers should be blocked.
- 4
Fix file:// assumed to work
easy8 minModule scripts generally need a real server protocol.
- 5
Fix nomodule chosen for a supporting browser
easy8 minA module-aware browser should run the module script, not the fallback.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace