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
Read the hostname
easy10 minParse a URL and report its host.
- 2
Read the path
easy10 minParse a URL and report its path.
- 3
Read a query parameter
easy10 minParse the query string and read the id.
- 4
Handle a missing parameter
easy10 minReport what a missing parameter gives back.
- 5
Build a query string
medium10 minBuild a query string from two parameters.
Find the bug(5)
- 1
Fix search read without URLSearchParams
easy8 minThe raw search string still has the question mark and the key attached.
- 2
Fix pathname read as hostname
easy8 minhostname and pathname give different parts of the URL.
- 3
Fix the missing parameter unchecked
easy8 minA missing parameter gives null, which must be checked.
- 4
Fix the query string built by hand
easy8 minJoining strings misses the escaping a real query string needs.
- 5
Fix the parameter never set
easy8 minThe 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