Challenge 1 — Solution Task: Write an async function fetchAllUsers() using the while-loop pagination pattern from this chapter, against https://jsonplaceholder.typicode.com/users (this particular API returns all results in one page, so simulate hasMore by stopping once the returned array's length is 0 on a fake "page 2"). Log the total count fetched. async function fetchPage(pageNumber) { // jsonplaceholder doesn't really paginate /users, so page 2+ // is simulated as always empty to demonstrate the loop's exit if (pageNumber > 1) { return []; } const response = await fetch("https://jsonplaceholder.typicode.com/users"); return response.json(); } async function fetchAllUsers() { let page = 1; let allUsers = []; let hasMore = true; while (hasMore) { const data = await fetchPage(page); allUsers = [...allUsers, ...data]; hasMore = data.length > 0; page++; } return allUsers; } fetchAllUsers().then(users => console.log("Total users:", users.length)); Expected output: Total users: 10 Notes: - fetchPage simulates real pagination behaviour even though the underlying API doesn't actually paginate — page 1 returns the real 10 users, and every page after that returns an empty array, exactly mimicking "no more pages left." - hasMore = data.length > 0 is what actually drives the loop's exit condition — once a page comes back empty, the while loop stops on its next check. - allUsers = [...allUsers, ...data] merges each page's results using spread (Intermediate Chapter 1), the same merging technique shown in this chapter's main pagination example.