Project: orders in sequence
JavaScript · Unit 18: Asynchronous code
- Full plan
- JavaScript
- Project
- 3 exercises
The practice comes with a parcel tracker: api + "/paquete/" + code answers with the code, its state and the days left, which it calls dias.
The codes that exist are 7 and 9. With any other one the answer still arrives, but with ok as false and no parcel data in it.
const api = "https://api.bybecode.dev";
const u = api + "/paquete/7";
const r = await fetch(u);
const d = await r.json();
console.log(d.dias);Prints
2
Exercises in this lesson
You do them in the app, which checks them on the spot and explains why.
1. Complete the code
Fill in
exists(code), which answers whether that address has a parcel.2. Write the code
Write
daysLeft(code): the days the parcel still has left, or -1 if that address has no parcel at all.3. Write the code
Write
allDays(codes): an array with the days left for every code, in the same order. The requests don't depend on each other, so they go together withPromise.all. ThedaysLeftfunction is already written above.
It opens in your browser. This lesson is part of the full plan; the first unit of each course is free.