JavaScript Create a Reusable Fetch Function

Jerome vanGaalen
Jerome vanGaalen
18,789 Points

Only first image loads.

When I refresh or load the page the first random image appears, but if I click the card, or try to select a breed, I get a broken image on the page and an error 4404 not found message in the console.

https://w.trhou.se/fro5pcf7n7

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Jerome vanGaalen! You're doing well, and this all comes down to some punctuation. On line 44 of app.js you are using single quotes where you should be using backticks. So instead of it looking for the breed you selected it's literally searching for ${breed} instead of say Labrador.

Line 44 of app.js right now:

fetchData('https://dog.ceo/api/breed/${breed}/images/random')

But that should be:

// note the backticks instead of single quotes
fetchData(`https://dog.ceo/api/breed/${breed}/images/random`)

Hope this helps! :sparkles: