Skip to content

Instantly share code, notes, and snippets.

@dharmakshetri
Created August 30, 2017 05:50
Show Gist options
  • Save dharmakshetri/478177c583644dc1063315c4321d40ae to your computer and use it in GitHub Desktop.
Save dharmakshetri/478177c583644dc1063315c4321d40ae to your computer and use it in GitHub Desktop.
function addImage(data) {
let htmlContent = '';
const firstImage = data.results[0];
if (firstImage) {
htmlContent = `<figure>
<img src="${firstImage.urls.small}" alt="${searchedForText}">
<figcaption>${searchedForText} by ${firstImage.user.name}</figcaption>
</figure>`;
} else {
htmlContent = 'Unfortunately, no image was returned for your search.'
}
responseContainer.insertAdjacentHTML('afterbegin', htmlContent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment