Skip to main content

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

    Save an object

    easy10 min

    Save a user object and read the name back.

  2. 2

    Save an array

    easy10 min

    Save a list of tags and count them after loading.

  3. 3

    Use a default when nothing is saved

    easy10 min

    Fall back to an empty object when the key is missing.

  4. 4

    Update a stored object

    easy10 min

    Load, change a property, and save it again.

  5. 5

    Recover from bad data

    medium10 min

    Catch a parse failure and fall back to a default.

Find the bug(5)

  1. 1

    Fix the object saved directly

    easy8 min

    Without stringify the object becomes useless text.

  2. 2

    Fix the missing parse

    easy8 min

    The saved value is still a JSON string until parsed.

  3. 3

    Fix JSON.parse called on a missing key

    easy8 min

    JSON.parse(null) quietly parses as the value null instead of an object.

  4. 4

    Fix the update never saved back

    easy8 min

    Changing the loaded object does not save it automatically.

  5. 5

    Fix the unguarded parse of bad data

    easy8 min

    Invalid 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