Skip to main content

JavaScript location Object — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript location Object 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

    Read the hostname

    easy10 min

    Parse a URL and report its host.

  2. 2

    Read the path

    easy10 min

    Parse a URL and report its path.

  3. 3

    Read a query parameter

    easy10 min

    Parse the query string and read the id.

  4. 4

    Handle a missing parameter

    easy10 min

    Report what a missing parameter gives back.

  5. 5

    Build a query string

    medium10 min

    Build a query string from two parameters.

Find the bug(5)

  1. 1

    Fix search read without URLSearchParams

    easy8 min

    The raw search string still has the question mark and the key attached.

  2. 2

    Fix pathname read as hostname

    easy8 min

    hostname and pathname give different parts of the URL.

  3. 3

    Fix the missing parameter unchecked

    easy8 min

    A missing parameter gives null, which must be checked.

  4. 4

    Fix the query string built by hand

    easy8 min

    Joining strings misses the escaping a real query string needs.

  5. 5

    Fix the parameter never set

    easy8 min

    The value must be set before toString includes it.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace