Skip to main content

Practice ยท 1 of 1

Load a User from an API

A fake fetch is provided that returns a promise resolving to a response object with .ok (true) and .json() (resolves to { name: "Ada", role: "learner" }). 1. Write an async function loadUser() that awaits fetch("https://api.example.com/me"), checks response.ok (throw on failure), awaits response.json(), and RETURNS the parsed user object. 2. Call loadUser() and log the returned user's name โ€” should print Ada.

Difficulty: intermediate

Back to lesson: Practice: Talking to Servers: fetch and APIs โ€” Practice