var divArray = []; var drinkArray = []; var meetMixMe = $(".meetMixMe") //function that generates random drink on pageload pageLoad(); //keyup function allows a user to fire search function by pressing enter and prevents enter from resetting page $("#tempSearchBar").keyup(function () { if (event.which == 13) { divArray = []; drinkArray = []; $("#container").empty(); $("#container2").empty(); $(".meetMixMe").empty(); var ingredient = $("#tempSearchBar").val().trim(); var queryURL = "https://www.thecocktaildb.com/api/json/v1/1/filter.php?i=" + ingredient; //ajax call to get drink info $.ajax({ url: queryURL, method: "GET" }).then(function (response) { // this IF statement alerts a user if the value of their input is not adequate for the ajax if (response == "") { $("#tempSearchBar").val("Not a valid ingredient, please try again") $("#tempSearchBar").attr("class", "error"); } else $("#tempSearchBar").attr("class", "errorFix"); for (var i = 0; i < response.drinks.length; i++) { //For loop that runs to create the divs with drink info var newDiv = $("
"); $("#container").append(newDiv); var newArticle = $("
"); newArticle.attr("class", "article-row grid-y"); var clickPic = $(""); clickPic.attr("class", "clickable") clickPic.attr("id", response.drinks[i].idDrink) clickPic.append(newArticle); newDiv.append(clickPic) var newDiv = $("
"); newDiv.attr("class", "article-row-img grid-x align-center"); newArticle.append(newDiv); var newImg = $(""); newImg.attr("src", response.drinks[i].strDrinkThumb); newImg.attr("id", "product") newDiv.append(newImg); var divTitle = $("
"); divTitle.attr("class", `article-row-content ${[i]}`); newArticle.append(divTitle); var newH3 = $("

"); newH3.attr("class", "article-row-content-header"); newH3.text(response.drinks[i].strDrink); divTitle.append(newH3); divArray.push(divTitle); var drinkId = response.drinks[i].idDrink; drinkArray.push(drinkId) } //click function to initiate search when you click a drink to take you to the full details $(".clickable").on("click", function () { var clickedId = $(this).attr("id"); //function that takes the idea of first ajax and uses it to search a second ajax call by ID function getInstructions(num) { var drinkIngredients = "https://www.thecocktaildb.com/api/json/v1/1/lookup.php?i=" + num; $.ajax({ url: drinkIngredients, method: "GET" }).then(function (data) { divArray = []; drinkArray = []; $("#container").empty(); $("#container2").empty(); console.log(data); var newerDiv = $("
"); newerDiv.attr("class", "grid-x align-center") $("#container2").append(newerDiv); var drinkInfoDiv = $("
"); drinkInfoDiv.attr("class", "medium-6 drink-info"); newerDiv.append(drinkInfoDiv); var secondDiv = $("
"); secondDiv.attr("class", "drink-name"); drinkInfoDiv.append(secondDiv); var newerImg = $(""); newerImg.attr("src", data.drinks[0].strDrinkThumb); newerImg.attr("class", "featured-drink") secondDiv.append(newerImg); var newerH3 = $("

"); newerH3.attr("class", "drinkName"); newerH3.text(data.drinks[0].strDrink); drinkInfoDiv.append(newerH3); var newH5 = $("

"); newH5.text("Ingredients:"); drinkInfoDiv.append(newH5); var newUl = $("