JavaScript Recap
No new theory, just a challenge that uses async and await, fetch and JSON, a loading state, response.ok, throw, try, catch and finally, a button to try again, and destructuring.
Mission: The crew panel
What you will see: under the biggest crews, a part with the heading "Crew". While it loads, a line says Loading the crew.... Then the line says Crew on board: 6, and a list shows:
Vega, Commander
Orion, Pilot
Lyra, Engineer
...
When the crew can't load, the line says something like Couldn't load the crew: The tracker answered 503, and a Try again button shows.
The tracker counts the crew, but never says who they are. Give the crew their own panel, with everything a good loading part has.
- After the list
biggest-crews, add a section with the idcrew-panel, and a heading. - In it, add a paragraph with the id
crew-status, which a screen reader reads out politely. It saysLoadingat first. - Add a button of type
buttonwith the idcrew-again, hidden. - Add a list with the id
crew, busy at first. - An
asyncfunction loadshttps://cyberstars.app/api/practice/crewwhen the page opens. - The list is busy while it loads, and isn't when it's done, whatever happened.
- When everything goes well, the list has an item for each person: their name, a comma and a space, then their role, in the API's order.
- Then
#crew-statussaysCrew on board:, then how many there are. - When the answer isn't ok, or there is no connection,
#crew-statussaysCouldn't load the crew:, then the error's message, and#crew-againshows. - A click on it hides it, puts
Loadingback in#crew-status, and loads again.
An answer that is an error doesn't throw an error by itself.