Intermediate
Remember the visitor's name
Write greeting() that returns Welcome back, NAME when localStorage has a name, and Hello, stranger otherwise. Show it in #greeting when the page loads.
When Save is clicked, store the trimmed input under the key name and update #greeting. Ignore empty or blank names.
(Hectal's preview keeps storage in memory, so it resets on each Run. On a real site the greeting survives a reload.)
What Check tests
- With nothing stored,
greeting()returnsHello, stranger - The page shows a greeting on load
- Save stores the trimmed name under
name - After saving, the page says
Welcome back, Asha greeting()reads whatever is stored- A blank name isn't saved
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.