Save it and fetch it

Cheat sheet · Level 1

Remember it

Every command and idea of this level on one page: what to type, what it does, and what you see.

Take the level exam
  1. 1Save it on the phone

    Keep a value after the app closes.

    What to typeWhat it doesYou see
    localStorage.setItem("name", input.value);Save the name on the phone·
  2. 2Read it back

    Open the app and find your name.

    What to typeWhat it doesYou see
    const name = localStorage.getItem("name");Read the saved nameWelcome back, Mia
  3. 3A brand-new phone

    Nothing saved? Use a default.

    What to typeWhat it doesYou see
    const name = localStorage.getItem("name") || "friend";A default when nothing is savedWelcome back, friend
  4. 4Save the whole list

    Turn a list into text first.

    What to typeWhat it doesYou see
    localStorage.setItem("items", JSON.stringify(items));Turn the list into text["Milk","Eggs"]
  5. 5Open with the list ready

    Turn the text back into a list.

    What to typeWhat it doesYou see
    let items = JSON.parse(localStorage.getItem("items") || "[]");Turn the text back into a list·
  6. 6Start a new list

    Delete what was saved.

    What to typeWhat it doesYou see
    localStorage.removeItem("items");Delete the saved list·
  7. 7On your own: the reading log

    Make it remember.

    What to typeWhat it doesYou see
    let books = JSON.parse(localStorage.getItem("books") || "[]");Start from the saved list·
    localStorage.setItem("books", JSON.stringify(books));Save after each Add·
    localStorage.removeItem("books");Clear deletes the jar·