Cocktail Recipe Generator

Suggested Cocktail Recipe:

Ingredients: ${getIngredients(cocktail).join(", ")}

Instructions: ${cocktail.strInstructions}

`; cocktailRecipeDiv.appendChild(recipeDiv); }) .catch(error => console.error('Error fetching cocktail details:', error)); }); } catch (error) { cocktailRecipeDiv.innerHTML = '

Error fetching cocktail data. Please try again later.

'; } } // Function to extract ingredients from the cocktail object function getIngredients(cocktail) { const ingredients = []; for (let i = 1; i <= 15; i++) { if (cocktail[`strIngredient${i}`]) { ingredients.push(cocktail[`strIngredient${i}`]); } } return ingredients; } // Add event listener to the "Generate Recipe" button document.getElementById('generateRecipe').addEventListener('click', generateCocktailRecipe);
Scroll to Top