const imgRequest = new XMLHttpRequest(); imgRequest.onload = addImage; imgRequest.open('GET', 'https://api.unsplash.com/photos?page=1&query=${searchedForText}'); imgRequest.setRequestHeader('Authorization', 'Client-ID <client-id-here>'); imgRequest.send();
function addImage(){ const data = JSON.parse(this.responseText); const firstImage = datat.results[0]; responseContainer.insertAdjacementHTML('afterbegin', <figure> <img src="${firstImage.urls.small}" alt="${searchedForText}"> <figcaption>${searchedForText} by ${firstImage.user.name}</figcaption> </figure> ); }