Command Palette

Search for a command to run...

Hectal
Phase 10: AI Product UX
AI Frontend · Exercise 4 of 5 PreviousNext
Intermediate

Keep the Draft

Save what the person types in #prompt under the localStorage key mitra-draft on every change. When the page starts (and when #reload is clicked, which pretends the tab was reopened), put the saved text back in the box.

Clicking #send adds the text to #sent, empties the box and removes the saved draft, so a reload shows an empty box. Storage can throw (it is full or blocked): typing must keep working, so wrap every storage call in try/catch.

What Check tests

  1. Typing saves the draft under mitra-draft
  2. After a reload the box holds the draft
  3. Send adds the text, empties the box and removes the draft
  4. After sending and reloading, the box is empty
  5. If storage throws, typing still works

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.