Skip to main content

Practice ยท 2 of 2

Check response.ok Before Using It

Write async function loadUser() that fetches https://api.example.com/me, throws new Error("HTTP " + response.status) when response.ok is false, and otherwise returns the parsed JSON. Then call it and log the user's name (the provided fetch resolves with a working response). Rules: - await both the fetch and .json(). - Guard with if (!response.ok).

Difficulty: beginner

Back to lesson: Practice: Asynchronous JavaScript: Promises and async/await โ€” Practice