Command Palette

Search for a command to run...

Hectal
Phase 11: Network and Browser APIs
JavaScript · Exercise 5 of 5 Previous
Intermediate

A user loader with loading, errors and retries

api(id) is a fake fetch (don't change it): id 1 and 2 reply 200 with a user, other ids reply 404, and id 0 fails like a network error.

When Load is clicked: show Loading… in #status and disable the button, then show the user's name, or User not found for a 404, or a message starting with Network error when the request fails. Re-enable the button whatever happens.

What Check tests

  1. Clicking Load shows Loading… and disables the button
  2. Id 1 shows Asha Rao and re-enables the button
  3. Id 7 shows User not found
  4. Id 0 shows a Network error message and re-enables the button
  5. No uncaught errors

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.