Hi Shaun - Love job here! š„³
One thing I would suggest in your JS is to add a check to ensure the API has responded correctly, and render an error message if not. This isn't too tricky, and I would just change the data
variable to be something like:
await response => response.ok ? response.json() : throw new Error("API Failed")
If you then wrap the inside of the fetchAdvice
function in a try catch statement can render some fallback text in case things don't work for any reason. It's not a big deal, but thinking about how things can go wrong is a good habit to get into, something like:
const fetchAdvice = async() => {
try {
const res ...
const data ....
// rest of your code
}
catch {
document.getElementById("text").innerHTML = `"Sorry error or whatever"`
}
Hope this helps.
Cheers š
Dave
Marked as helpful