function displayPhotos() {
    imagesLoaded = 0;
    totalImages = photosArray.length;

    // Run function for each object in photosArray.
    photosArray.forEach((photo) => {

        // Create <a> to link to Unsplash
        const item = document.createElement('a');
        setAttributes(item, {
            href: photo.links.html,
            target: '_blank'
        });

        // Create <img> for photo
        const img = document.createElement('img');
        setAttributes(img, {
            src: photo.urls.regular,
            alt: photo.alt_description,
            title: photo.alt_description
        });

        // Event Listner, check when each image has finished loading
        img.addEventListener("load", imageLoaded);

        // Put <img> inside <a>, then insert in to imageContainer
        item.appendChild(img);
        imageContainer.appendChild(item);
    });
}
// Create elements for links & Photos, Add to DOM
Create elements for links & Photos, Add to DOM
Create elements for links & Photos Add to DOM
function displayPhotos() {
    imagesLoaded = 0;
    totalImages = photosArray.length;
    photosArray.forEach((photo) => {
        const item = document.createElement('a');
        setAttributes(item, {
            href: photo.links.html,
            target: '_blank'
        });
        const img = document.createElement('img');
        setAttributes(img, {
            src: photo.urls.regular,
            alt: photo.alt_description,
            title: photo.alt_description
        });
        img.addEventListener("load", imageLoaded);
        item.appendChild(img);
        imageContainer.appendChild(item);
    });
}
function displayPhotos ( ) { imagesLoaded = 0 ; totalImages = photosArray . length ; photosArray . forEach ( ( photo ) => { const item = document . createElement ( 'a' ) ; setAttributes ( item , { href : photo . links . html , target : '_blank' } ) ; const img = document . createElement ( 'img' ) ; setAttributes ( img , { src : photo . urls . regular , alt : photo . alt_description , title : photo . alt_description } ) ; img . addEventListener ( "load" , imageLoaded ) ; item . appendChild ( img ) ; imageContainer . appendChild ( item ) ; } ) ; }
Create elements for links & Photos, Add to DOM
Create elements for links & Photos Add to DOM
// Run function for each object in photosArray. // Create <a> to link to Unsplash // Create <img> for photo // Event Listner, check when each image has finished loading // Put <img> inside <a>, then insert in to imageContainer