Sikau

Web essentials · Day 8 · about 40 min

Project: Notes app

Forms, delegation and storage together.

A small, complete app

Build a notes app: add notes with a form, delete them with one delegated listener, and keep them in localStorage so they survive a reload.

The app's moving parts

Small as it is, this app has the same architecture as much bigger ones: state, rendering, events and persistence, each with a clear job.

This small app uses every idea from the unit together. The data is an array of { id, text } notes. render() draws that array as list items. The form adds notes. One delegated listener on the list deletes them. localStorage saves the array after every change and loads it at start-up. Each piece is simple; the skill is wiring them in a clean loop.

let notes = load();

function save() { localStorage.setItem("notes:v1", JSON.stringify(notes)); }

form.addEventListener("submit", (e) => {
  e.preventDefault();
  const text = input.value.trim();
  if (!text) return;
  notes = [...notes, { id: Date.now(), text }];
  save(); render(); form.reset();
});

Ids matter for deleting: the button's data-id connects what was clicked to an item in the array. Remember that dataset values are always strings, while Date.now() ids are numbers — compare them as the same type.

The rest of this lesson

  • Safe and resilientexplain
  • Deleting a noteorder
  • String or number?predict
  • Unit skill → app partmatch
  • Build the notes appchallenge
  • Badge quizquiz
  • Unit 2 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 16 lessons of Web essentials