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

I'm trying to copy the code exactly as it's working in the video, but I'm getting the error "data.map is not a function"

Here is a snapshot of my workspace


2 Answers

Steven Parker
Steven Parker
216,744 Points

It appears that the API for the more extensive "all" list is a bit different from the one used in the video. In the video, the standard list clearly returns an array; but this one seems to be returning an object instead with breed keys and sub-breed arrays as values.

The "map" method is only available on arrays, but here's a revised "generateOptions" function that will work with the object that I fetched using your URL today:

function generateOptions(data) {
  let options = "";
  for (item in data) {
    if (data[item].length > 0) {
      data[item].forEach(sb => options += `
    <option value='${sb} ${item}'>${sb} ${item}</option> 
    } else {
      options += `
    <option value='${item}'>${item}</option> 
  select.innerHTML = options;

I've alerted the staff about this. I doubt they can change the video but they might add a notice to the teacher's notes about the new API.

Mohammed Ali
Mohammed Ali
11,132 Points

Thanks Steven - It no longer return array but rather object as you said. Def works, thanks.

Guil Hernandez
Guil Hernandez
Treehouse Teacher

Hi Ryan Pierson,

It looks like the endpoint shown in the video (and posted in the teacher's notes) still returns the array of breeds. If you remove /all from your URL it should work: https://dog.ceo/api/breeds/list.

Thanks for looking into this and your awesome suggestion, Steven Parker! I'll add an instruction step to the workshop regarding the API changes.

Hope this helps. :)

Aiden Berzins
Aiden Berzins
23,837 Points

Just a note for those coming through to this video much later. This is still a solution that works as of 4/22/19.