Recipe Finder

async function fetchRecipes() { const ingredientInput = document.getElementById("ingredientInput").value; const API_KEY = "YOUR_SPOONACULAR_API_KEY"; // Replace with your API key const API_URL = `https://api.spoonacular.com/recipes/findByIngredients?ingredients=${ingredientInput}&number=10&apiKey=${API_KEY}`; try { const response = await fetch(API_URL); const recipes = await response.json(); displayRecipes(recipes); } catch (error) { console.error("Error fetching recipes:", error); } } function displayRecipes(recipes) { const recipesContainer = document.getElementById("recipes"); recipesContainer.innerHTML = ""; recipes.forEach(recipe => { const recipeElement = document.createElement("div"); recipeElement.classList.add("recipe"); recipeElement.innerHTML = `

${recipe.title}

${recipe.title}

Used Ingredients: ${recipe.usedIngredientCount}

Missing Ingredients: ${recipe.missedIngredientCount}

`; recipesContainer.appendChild(recipeElement); }); }