JavaScript AJAX Basics (retiring) AJAX and APIs Stage 4 Challenge Answer

Bethany Cooksey
Bethany Cooksey
14,241 Points

My Solution to the Optional Challenge

 function displayPhotos(data) {
      if(data.items.length == 0) {
      var photoHTML = '<p>There are not any pictures that match ' + animal + '.</p>';
       } else {
          var photoHTML = '<ul>';
          $.each(data.items,function(i,photo) {
            photoHTML += '<li class="grid-25 tablet-grid-50">';
            photoHTML += '<a href="' + photo.link + '" class="image">';
            photoHTML += '<img src="' + photo.media.m + '"></a></li>';

          }); // end each

          photoHTML += '</ul>';
      }
      $('#photos').html(photoHTML);