Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,095 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