Skip to main content

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. 1

    Simulate deferred loading

    easy10 min

    Show that reading an element only works once the page is ready.

  2. 2

    Show it runs once

    easy10 min

    Simulate a module loaded twice sharing one execution.

  3. 3

    Report the CORS requirement

    easy10 min

    Report that a cross-origin module needs a CORS-friendly response.

  4. 4

    Report the file protocol limit

    easy10 min

    Report that module scripts need a real server.

  5. 5

    Simulate nomodule fallback

    medium10 min

    Report which script a module-aware browser runs.

Find the bug(5)

  1. 1

    Fix the element read before it exists

    easy8 min

    Reading before the page is ready gives nothing.

  2. 2

    Fix the module counted as loaded twice

    easy8 min

    A module included twice should still only run once.

  3. 3

    Fix CORS assumed to always allow

    easy8 min

    A cross-origin module without CORS headers should be blocked.

  4. 4

    Fix file:// assumed to work

    easy8 min

    Module scripts generally need a real server protocol.

  5. 5

    Fix nomodule chosen for a supporting browser

    easy8 min

    A 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