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 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
seal-mask
.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> ;