Day 11 - Exceptions, More Looping
Housekeeping
- Marking delayed due to course outline update season
1. Handing Exceptions with async/await
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/10https://zoo-animal-BROKEN-api.herokuapp.com/animals/rand/10 - Add a
try/catchthat 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/10https://zoo-animal-api.herokuapp.com/BROKEN/rand/10 - Throw a custom error by testing for a
truevalue onresponse.okso that the page displays a custom “404 Not Found” error for the user.
2. Array.forEach() and Higher Order Array Methods
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

