Skip to main content

JavaScript sessionStorage — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript sessionStorage 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

    easy10 min

    Save a step number and read it back.

  2. 2

    Store form progress

    easy10 min

    Save an object as JSON for a form step.

  3. 3

    Remove a session value

    easy10 min

    Set and then remove a key, and report it is gone.

  4. 4

    Store a count as text

    easy10 min

    Show that a stored number comes back as a string.

  5. 5

    Use both storages together

    medium10 min

    Save one value in each and read both back.

Find the bug(5)

  1. 1

    Fix localStorage used for temporary data

    easy8 min

    Data that should not outlive the tab belongs in sessionStorage, not localStorage.

  2. 2

    Fix the object saved without stringify

    easy8 min

    Without JSON.stringify the object becomes useless text.

  3. 3

    Fix the stored count added like a number

    easy8 min

    The stored value is text, so plus joins instead of adding.

  4. 4

    Fix the wrong storage read back

    easy8 min

    The value was saved in one storage and read from the other.

  5. 5

    Fix removeItem given the wrong key

    easy8 min

    The key passed to removeItem must match exactly.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace