Skip to main content

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

    Save and read a value

    easy10 min

    Save a name and read it back.

  2. 2

    Read a missing key

    easy10 min

    Report what a key that was never set gives back.

  3. 3

    Remove a value

    easy10 min

    Save two keys, remove one, and report which remain.

  4. 4

    Check the stored type

    easy10 min

    Save a number and report the type it comes back as.

  5. 5

    Clear everything

    medium10 min

    Save two keys, clear storage, and report the length.

Find the bug(5)

  1. 1

    Fix the number never converted back

    easy8 min

    A stored number reads back as text.

  2. 2

    Fix the value read with the wrong key

    easy8 min

    The key used to read must match the one used to save.

  3. 3

    Fix the wrong key removed

    easy8 min

    removeItem was given a key that does not exist.

  4. 4

    Fix the missing key unchecked

    easy8 min

    A missing key gives null, not an error, but code must still check.

  5. 5

    Fix removeItem used to clear everything

    easy8 min

    removeItem 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