Use the two-step fetch chain to report the name.
Acceptance criteria
- 1.#out should show Ada.
JavaScript Tutorial · JavaScript Asynchronous
These 10 tasks go with the JavaScript Fetch API chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “fetch requests data from a server and returns a promise.” .
1.Read JSON from a responseexercise · easy · 10 min
Use the two-step fetch chain to report the name.
Passes when: #out should show Ada.
2.Use await insteadexercise · easy · 10 min · practice plan
Rewrite the same request with async and await.
Passes when: #out should show Grace.
3.Check the statusexercise · easy · 10 min · practice plan
Report the failure when response.ok is false.
Passes when: #out should show failed with 404.
4.Catch a network failureexercise · easy · 10 min · practice plan
Catch a rejected fetch and report the message.
Passes when: #out should show network down.
5.Send dataexercise · medium · 10 min · practice plan
Send a name in the body and report what came back.
Passes when: #out should show Alan.
6.Fix the response used as the databug fix · easy · 8 min
The response is not the body; json() must be called.
Passes when: #out should show Ada.
7.Fix the missing await on jsonbug fix · easy · 8 min · practice plan
json() returns a promise, so its value must be awaited.
Passes when: #out should show Grace.
8.Fix the status never checkedbug fix · easy · 8 min · practice plan
fetch does not reject on 404, so response.ok must be tested.
Passes when: #out should show failed with 404.
9.Fix the object sent without stringifybug fix · easy · 8 min · practice plan
The body must be a string.
Passes when: #out should show Alan.
10.Fix json used on plain textbug fix · easy · 8 min · practice plan
A text response should be read with text().
Passes when: #out should show hello.
Between them these tasks cover fetch, response.json and response.ok.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.