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 Displaying the Content

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 29,363 Points

API update

I think this video needs update as API has changed. That list is not available any more. Now under Documentation there is only "List all breeds" list available as an object not an array. I had to code different function to make it work. You can see it below:

function generateOptions(data){
    let breedList = [];
    for(let prop in data){
        breedList.push(prop);
    }
    const options = breedList.map(item =>`
        <option value="${item}">${item}</option>
    `);
    select.innerHTML = options;
}

What do you think about my solution?

2 Answers

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hey Piotr Manczak 👋

I just had a look at the video as well as the response given by the API, but things seem to be the same as Guil is showing in the video. The endpoint for the list of breeds is returning an object with a success and message property. The array of breed names can be accessed through the message property as Guil is showing in the video around the 2:53 minute mark.

If you pass down that data.message array to your function you should be able to map over that data parameter right away instead of pushing each property to a new array beforehand.

function generateOptions(data) {
  const options = data.map(item => `
    <option value='${item}'>${item}</option>
  `).join('');
  select.innerHTML = options;
}

Hope this helps! 🙂

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 29,363 Points

Thank your for your answer. I must have missed something. At least I had some practice with iterating over objects. I needed to refresh some knowledge in that area of JS.