Await a resolved promise inside an async function and report the value.
Acceptance criteria
- 1.#out should show got Ada.
JavaScript Tutorial · JavaScript Asynchronous
These 10 tasks go with the JavaScript async and await 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: “async and await let you write asynchronous code that reads like ordinary code.” .
1.Await a promiseexercise · easy · 10 min
Await a resolved promise inside an async function and report the value.
Passes when: #out should show got Ada.
2.Await a timerexercise · easy · 10 min · practice plan
Await a promise that resolves from a timer.
Passes when: #out should show arrived.
3.Await twice in a rowexercise · easy · 10 min · practice plan
Await two steps in sequence and report the combined result.
Passes when: #out should show one two.
4.Await inside a loopexercise · easy · 10 min · practice plan
Total three awaited values in a loop.
Passes when: #out should show 12.
5.Show an async function returns a promiseexercise · medium · 10 min · practice plan
Report whether calling an async function gives back a promise.
Passes when: #out should show true.
6.Fix the missing awaitbug fix · easy · 8 min
Without await you get the promise, not the value.
Passes when: #out should show got Ada.
7.Fix the missing async keywordbug fix · easy · 8 min · practice plan
await only works inside an async function.
Passes when: #out should show ready.
8.Fix the value read after the callbug fix · easy · 8 min · practice plan
The async function has not finished when the next line runs.
Passes when: #out should show done.
9.Fix the total added before awaitingbug fix · easy · 8 min · practice plan
The promise itself is being added instead of its value.
Passes when: #out should show 12.
10.Fix the async function never calledbug fix · easy · 8 min · practice plan
Defining an async function does not run it.
Passes when: #out should show started.
Between them these tasks cover async, await and Async functions.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.