JavaScript localStorage — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript localStorage 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
Save and read a value
easy10 minSave a name and read it back.
- 2
Read a missing key
easy10 minReport what a key that was never set gives back.
- 3
Remove a value
easy10 minSave two keys, remove one, and report which remain.
- 4
Check the stored type
easy10 minSave a number and report the type it comes back as.
- 5
Clear everything
medium10 minSave two keys, clear storage, and report the length.
Find the bug(5)
- 1
Fix the number never converted back
easy8 minA stored number reads back as text.
- 2
Fix the value read with the wrong key
easy8 minThe key used to read must match the one used to save.
- 3
Fix the wrong key removed
easy8 minremoveItem was given a key that does not exist.
- 4
Fix the missing key unchecked
easy8 minA missing key gives null, not an error, but code must still check.
- 5
Fix removeItem used to clear everything
easy8 minremoveItem takes one key at a time; clear removes every key in one call.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace