Day 11 - Exceptions, More Looping
Housekeeping
- Marking delayed due to course outline update season
async
/await
1. Handing Exceptions with
Demo: Adding error handling to JSON Placeholder
Activity: Add error handling to zoo example
Instructions
- Copy the sample code into your workspace
- Edit the URL so that the domain is non-existent:
Break the domain:https://zoo-animal-api.herokuapp.com/animals/rand/10
https://zoo-animal-BROKEN-api.herokuapp.com/animals/rand/10
- Add a
try
/catch
that outputs an error to the user instead of a blank page; - Fix the domain and instead break the path:
Break the path:https://zoo-animal-api.herokuapp.com/animals/rand/10
https://zoo-animal-api.herokuapp.com/BROKEN/rand/10
- Throw a custom error by testing for a
true
value onresponse.ok
so that the page displays a custom “404 Not Found” error for the user.
Array.forEach()
and Higher Order Array Methods
2.
Demo: Looping through JSON Placeholder
- Starter Code
Activity: Looping through zoo example
Instructions
- Copy the sample code into your workspace;
- Using
Array.forEach()
refactor the starter code so that all 10 zoo animals are displayed instead of one random one.
Lab Time
- Due Tonight: Achievements Round 2
- Individual Project
Prep
Errors and Exceptions
Looping with higher order functions
- MDN: Array.forEach()
- Free CodeCamp: JavaScript forEach – How to Loop Through an Array in JS
- Youtube: JavaScript Array forEach Method