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 trialDaniel Cranney
11,609 PointsSo frustrating. I don't see the profiles, and get 'TypeError: Cannot read property 'source' of undefined'
In the last video this error came up, even though my code matches this video. The same error exists in this stage so this video was mostly pointless.
4 Answers
Robert Manolis
Treehouse Guest TeacherHey Daniel Cranney and Justin Keiser, in the generateHTML function, where you're adding the img element, try changing that line to one of these, depending on which section you're on:
<img src="${data.thumbnail ? data.thumbnail.source : ''}">
Or
<img src="${person.thumbnail ? person.thumbnail.source : ''}">
The problem is that not all of the results have a thumbnail property. So you have to check that the property exists before trying to use it, and if it doesn't exist, you can just pass an empty string to the src attribute.
Justin Keiser
17,709 PointsI don't know how to fix it yet but the error boils down to some of the folks in space have the same name as multiple wikipedia entries. I noticed this earlier when there were empty section elements. https://teamtreehouse.com/community/same-code-and-still-getting-an-error
Justin Keiser
17,709 PointsThanks Robert Manolis, I actually found that answer somewhere else. It works, but I'd love to know how to resolve the wikipedia problem so all of the people in space display. I've checked and all of the folks currently in space have articles, they just share names with other people. This wasn't the case when the tutorial was made.
Robert Manolis
Treehouse Guest TeacherAhh, I see what you mean, Justin Keiser. You're talking about a way to handle the disambiguation pages. Yeah, that could be done. After checking out the docs for the wikipedia API, one way that comes to mind would involve reworking the getProfiles function. After making the initial wikiUrl + person.name request, you'd loop over the results, and for the ones that have a type property with a value of 'disambiguation', you'd make another request, but with a slightly different URL. Instead of page/summary/
, you'd use page/related
, and that would give you an array of non disambiguation pages. So you'd loop over those results, and work out a way to grab the one you want, like the one that has a description property that includes the term cosmonaut or astronaut. Something like that should work.
Josiah Schmidt
3,440 PointsThanks for this workaround. It seems to have done the trick. Funny enough, the astronaut that was causing me trouble (as of October 2024) was Li Cong, who apparently does not have his own Wikipedia page, but there is an 8th-century Chinese prince who does have his own Wikipedia page, so my page now shows this Tang Dynasty royal as floating around in space alongside 21st-century astronauts. Lol!