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
- Typing saves the draft under
mitra-draft - After a reload the box holds the draft
- Send adds the text, empties the box and removes the draft
- After sending and reloading, the box is empty
- 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.