-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (31 loc) · 1.25 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
document.getElementById('searchButton').addEventListener('click', function() {
const ingredient = document.getElementById('ingredientInput').value;
fetchRecipes(ingredient);
});
function fetchRecipes(ingredient) {
const appId = '14c41d78';
const appKey = '0d75f66ee04724ed4f7823b870d227f0';
const apiUrl = `https://api.edamam.com/api/recipes/v2?type=public&q=${ingredient}&app_id=${appId}&app_key=${appKey}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
displayRecipes(data.hits);
})
.catch(error => {
console.error('Error:', error);
});
}
function displayRecipes(recipes) {
const recipesDiv = document.getElementById('recipes');
recipesDiv.innerHTML = '';
recipes.forEach(recipeItem => {
const recipe = recipeItem.recipe;
const recipeElement = document.createElement('div');
recipeElement.classList.add('recipe-card');
recipeElement.innerHTML = `
<h3>${recipe.label}</h3>
<img src="${recipe.image}" alt="${recipe.label}">
<a href="${recipe.url}" target="_blank">View Full Recipe</a>`; // Adjust based on response structure
recipesDiv.appendChild(recipeElement);
});
}