JavaScript Storing Objects — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Storing Objects 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 an object
easy10 minSave a user object and read the name back.
- 2
Save an array
easy10 minSave a list of tags and count them after loading.
- 3
Use a default when nothing is saved
easy10 minFall back to an empty object when the key is missing.
- 4
Update a stored object
easy10 minLoad, change a property, and save it again.
- 5
Recover from bad data
medium10 minCatch a parse failure and fall back to a default.
Find the bug(5)
- 1
Fix the object saved directly
easy8 minWithout stringify the object becomes useless text.
- 2
Fix the missing parse
easy8 minThe saved value is still a JSON string until parsed.
- 3
Fix JSON.parse called on a missing key
easy8 minJSON.parse(null) quietly parses as the value null instead of an object.
- 4
Fix the update never saved back
easy8 minChanging the loaded object does not save it automatically.
- 5
Fix the unguarded parse of bad data
easy8 minInvalid JSON throws unless it is caught.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace