Command Palette

Search for a command to run...

Hectal
Phase 11: Network and Browser APIs
JavaScript · Exercise 3 of 5 PreviousNext
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

  1. With nothing stored, greeting() returns Hello, stranger
  2. The page shows a greeting on load
  3. Save stores the trimmed name under name
  4. After saving, the page says Welcome back, Asha
  5. greeting() reads whatever is stored
  6. 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.