Save a name and read it back.
Acceptance criteria
- 1.#out should show Ada.
JavaScript Tutorial · JavaScript Storage & BOM
These 10 tasks go with the JavaScript localStorage chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “localStorage saves data in the browser that survives closing the page.” .
1.Save and read a valueexercise · easy · 10 min
Save a name and read it back.
Passes when: #out should show Ada.
2.Read a missing keyexercise · easy · 10 min · practice plan
Report what a key that was never set gives back.
Passes when: #out should show nothing saved.
3.Remove a valueexercise · easy · 10 min · practice plan
Save two keys, remove one, and report which remain.
Passes when: #out should show b only.
4.Check the stored typeexercise · easy · 10 min · practice plan
Save a number and report the type it comes back as.
Passes when: #out should show string.
5.Clear everythingexercise · medium · 10 min · practice plan
Save two keys, clear storage, and report the length.
Passes when: #out should show 0.
6.Fix the number never converted backbug fix · easy · 8 min
A stored number reads back as text.
Passes when: #out should show 12.
7.Fix the value read with the wrong keybug fix · easy · 8 min · practice plan
The key used to read must match the one used to save.
Passes when: #out should show Ada.
8.Fix the wrong key removedbug fix · easy · 8 min · practice plan
removeItem was given a key that does not exist.
Passes when: #out should show gone.
9.Fix the missing key uncheckedbug fix · easy · 8 min · practice plan
A missing key gives null, not an error, but code must still check.
Passes when: #out should show nothing saved.
10.Fix removeItem used to clear everythingbug fix · easy · 8 min · practice plan
removeItem takes one key at a time; clear removes every key in one call.
Passes when: #out should show 0.
Between them these tasks cover setItem and getItem, removeItem and String values.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.