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 Asynchronous Programming with JavaScript Exploring Async/Await Convert Promise Handling to Async/Await

Rebecca Palumbo
Rebecca Palumbo
5,506 Points

Thumbnail missing, so how do I insert a different image for the missing image?

Okay, so for the second astronaut, there is no thumbnail image. Only the first astronaut loads. I can delete the <img src=${person.thumbnail.source}> from the generateHTML function and it'll work without pictures, but I was wondering if there's a way to skip over missing data instead of it crashing the rest of the page, or putting in a no picture image if there's no picture. How would I do this? I can't figure it out. My code looks like what Guil did, but here's a snapshot if you need it: https://w.trhou.se/lyufc4hqb4.

you could use an if statement checking if the response object has an image property or not, if not, show a default image.

1 Answer

Joseph Turner
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Turner
Full Stack JavaScript Techdegree Graduate 16,794 Points

I found that my "Andrew Morgan" astronaut was missing the "thumbnail". You can check the api resource to see "thumbnail is missing" : https://en.wikipedia.org/api/rest_v1/page/summary/Andrew_Morgan

So I did an if statement as Agustin suggested:

if(typeof(person.thumbnail) != 'undefined') { section.innerHTML = <img src=${person.thumbnail.source}> ; } section.innerHTML += <span>${person.craft}</span> <h2>${person.title}</h2> <p>${person.description}</p> <p>${person.extract}</p> ;