Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Create a Reusable Fetch Function

Image not showing

Following along with the video and I get the first image however when I click on other images they do not show.

please check out my workbook https://w.trhou.se/0ylsxi8v5i.

In the browser, I receive the error message

Breed%20not%20found%20(sub%20breed%20does%20not%20exist):1 Failed to load resource: the server responded with a status of 404 (Not Found).

Also, I am not getting the names of the breeds but numbers.

1 Answer

Steven Parker
Steven Parker
231,269 Points

It's normal for the keys of an array to just be numbers. So instead of the keys, use the data directly on line 27:

  const options = Object.keys(data).map(item =>  // original code
  const options = data.map(item =>               // suggested fix

Then on line 48, use the breed directly instead of as a sub-breed of "hound":

fetchData(`https://dog.ceo/api/breed/hound/${breed}/images/random`)  // original code
fetchData(`https://dog.ceo/api/breed/${breed}/images/random`)        // suggested fix