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 trialGavin Eyquem
Front End Web Development Techdegree Student 20,735 PointsTypeError: person.thumbnail is undefined.
I try to make sure the code is as shown in the video, but when I run the code I get the above error. It then points to line 73 in the JS file.
Can someone tell me what I'm missing?
Here's my code... function getProfiles(json) { const profiles = json.people.map( person => { return fetch(wikiUrl + person.name) .then(response => response.json()) }); return Promise.all(profiles); }
// Generate the markup for each profile function generateHTML(data) { data.forEach(person => { const section = document.createElement('section'); peopleList.appendChild(section);
// Check if request returns a 'standard' page from Wiki
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 =
<img src="img/profile.jpg" alt="ocean clouds seen from space">
<h2>${person.title}</h2>
<p>Results unavailable for ${person.title}</p>
${person.extract_html}
;
}
});
}
btn.addEventListener('click', (event) => { event.target.textContent = "Loading...";
fetch(astrosUrl) .then(response => response.json()) .then(getProfiles) .then(generateHTML) .catch(err => { peopleList.innerHTML = '<h3>Something went wrong!</h3>'; console.log(err); }) .finally( () => event.target.remove()) });
Steven Parker
231,265 PointsSteven Parker
231,265 PointsGavin Eyquem — A much better way to show what you are doing in a workspace is with a snapshot, which allows us to easily try out the code. Here's a video about making and sharing a snapshot.
You may also want to take a look at this video about Posting a Question.