<file_sep>$(document).ready(function() {
  var $btn = $('#run-mad-lib');
  var $mad_lib = $('.mad-lib');

  //grab all the input values
  var noun = $('#noun').val();
  var us_state = $('#us-state').val();
  var a = $('#adjective').val();
  var t_of_d = $('#type-of-drink').val();
  var slang = $('#slang').val();

  $btn.click(function() {
    // var words_array = [noun, us_state, a, t_of_d, slang]
    var words_array = ['cat', 'florida', 'happy', 'corona', 'dopest'];
    var gif_array = [];

    for (i = 0; i < words_array.length; i++) {
      $.ajax({
        url: "http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=" + words_array[i],
        async: false
      }).done(function(gif) {
        gif_array.push(gif.data.image_url);
      });
    }

    console.log(gif_array);

    //build DOM element
    var mad_lib_gif = "<div><p>Jimmy and Karen decided one day that they were going to get their whole family together for a";
    mad_lib_gif += "<img src='" + gif_array[0] + "'/>. ";
    mad_lib_gif += "They decided to go to <img src='" + gif_array[1] + "'/>. ";
    mad_lib_gif += "First to join them were Jim and Katie. Then Jamie, Jessica, Avery, Luke, Sydney, Connor and Jack followed.";
    mad_lib_gif += " They were all so <img src='" + gif_array[2] + "' />!";
    mad_lib_gif += " Once they got to <img src'" + gif_array[1] + "'/>, they immediately went straight to the toilet. It was so much fun!";
    mad_lib_gif += " Jim poured himself too many <img src='" + gif_array[3] + "'/>, and landed himself in the hospital! Oh no!";
    mad_lib_gif += " Then finally, Abhi, Brian & Brad arrived. This was cool, because they are the coolest <img src='" + gif_array[4] + "'/> out of the group.  Especially Abhi.";
    mad_lib_gif += "</div>";

    //attach to page
    $mad_lib.children().remove();
    $mad_lib.append(mad_lib_gif);
  });

})
