Script Valley
JavaScript in the Browser: DOM, Events & APIs
Asynchronous JavaScript and the Fetch API/Assessment

Practice & Assessment

Test your understanding of Asynchronous JavaScript and the Fetch API

Multiple Choice Questions

6
1

fetch('/api/data') resolves successfully. Does this guarantee the server returned a 200 response?

2

Why must you await res.json() separately after awaiting fetch()?

3

What does the event loop do when the call stack is empty?

4

An async function returns the number 5. What type does the caller receive?

5

You use AbortController to cancel a fetch. What error name is thrown?

6

Promise.all([p1, p2, p3]) โ€” one promise rejects. What happens?

Coding Challenges

1
1

GitHub User Profile Fetcher

Build a search UI with a text input (#username-input) and a Search button (#search-btn). On click, fetch https://api.github.com/users/{username} using async/await. While loading show 'Searching...' in #status. On success display the user's avatar (img), name, login, and public_repos count in #result. On error (network failure or 404) display a user-friendly error message. Implement a 6-second AbortController timeout. Input: GitHub username string. Output: profile card or error message. Constraint: handle loading, success, and error UI states explicitly. Estimated time: 25-30 minutes.

Medium

Mini Project

1

Live Weather Dashboard

Build a weather dashboard using the Open-Meteo API (free, no key required). Requirements: a city search input that uses the geocoding API (https://geocoding-api.open-meteo.com/v1/search?name={city}) to resolve coordinates, then fetches current weather from https://api.open-meteo.com/v1/forecast with temperature, windspeed, and weathercode parameters. Display current temperature, wind speed, and a text description derived from weathercode. Show loading spinner (classList toggle) during requests, an error state on failure, and a history section listing the last 5 searched cities using localStorage. Use async/await, AbortController for timeouts, and Promise.all when fetching geocoding and weather in sequence.

Hard
Practice & Assessment โ€” Asynchronous JavaScript and the Fetch API โ€” JavaScript in the Browser: DOM, Events & APIs โ€” Script Valley โ€” Script Valley