AI Frontend · Exercise 5 of 5 Previous
Intermediate
Save and Restore a Chat
A tiny Mitra: type in #prompt, click #send, and the question and the reply are added to #messages (one li each). The server route is done.
Make the conversation survive a reload. save() must write { version: 1, messages } as JSON under the key mitra:chat. load() must read it back. The #reload button calls start() again, as a page reload would.
load() must not crash on bad data: if the stored text is not valid JSON, or has no messages list, start with an empty chat.
What Check tests
- A question and its reply appear as two messages
- The chat is saved as JSON with
version: 1 - After a reload the two messages are back
- Half-written JSON gives an empty chat, not a crash
- A value with the wrong shape gives an empty chat
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.