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 Asynchronous Programming with JavaScript Understanding Promises Handle Multiple Promises with Promise.all

I'm not getting all the astronauts

I was only able to retrieve 3 of the 6 astronauts. This is what my page page looks like:

https://ibb.co/9V3wF8n

3 Answers

Hi Christian,

I had the same issue when I did it. I found that it is due to those astronauts not having a complete record come through from the Wikipedia API. I tweaked a bit the function so that it didn't show only the blank tile. See below how I added the HTML in an if statement and the else part is what creates the tile for astronauts who don't have a complete record coming through from the wiki API.

Have a look at my code below and see if it works for you. And let us know if it does!

Cheers, Daniel.

// Generate the markup for each profile
function generateHTML(data) {
  const section = document.createElement('section');
  peopleList.appendChild(section);
  if (data.type === "standard") {
    section.innerHTML = `
      <img src=${data.thumbnail.source}>
      <h2>${data.title}</h2>
      <p>${data.description}</p>
      <p>${data.extract}</p>
      `;
  } else {
    section.innerHTML = `
      <h2>${data.title}</h2>
      <p>No description available</p>
  `;
  }
}

Sorry, here is the code with Promise design instead.

// Generate the markup for each profile
function generateHTML(data) {
  data.map(person => {
    const section = document.createElement('section');
    peopleList.appendChild(section);
    if (person.type === "standard") {
      section.innerHTML = `
      <img src=${person.thumbnail.source}>
      <h2>${person.title}</h2>
      <p>${person.description}</p>
      <p>${person.extract}</p>`;
    } else {
      section.innerHTML = `
      <h2>${person.title}</h2>
      <p>No description available</p>`;
    }
  })
}

thanks! it worked

I had the same problem and the if statement inside the generateHTML function worked. Thanks Daniel. What does "standard" represent in the parameter of the if statement? (person.type === "standard)

function generateHTML(data) {
data.map( person => {
const section = document.createElement('section');
peopleList.appendChild(section);
section.innerHTML = `
<img src=${person.thumbnail.source}>
<h2>${person.title}</h2>
<p>${person.description}</p>
<p>${person.extract}</p>
`;
});
}

This doesn't work when the first astronaut fails to load, so using the @Daniel Barros 's code will fix the problem. +++