-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
31 lines (26 loc) · 1.01 KB
/
App.js
File metadata and controls
31 lines (26 loc) · 1.01 KB
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
const applicationID = "c496368a"
const applicationKey = "2933b144eb63370c2c800d17766dc7bb"
const inputField = document.querySelector("#textField")
const searchButton = document.querySelector("#submitButton")
const recipeContainer = document.querySelector("#recipeContainer")
const searchQuery = async () => {
const query = inputField.value
// const query = "pizza"
// console.log(query)
try {
const response = await fetch(`https://api.edamam.com/api/recipes/v2?type=public&q=${query}&app_id=${applicationID}&app_key=${applicationKey}`)
const data = await response.json();
data.hits.map((a) => {
// console.log(a.recipe)
const { image } = a.recipe
// create element image
const createImage = document.createElement("img")
createImage.src = image
recipeContainer.appendChild(createImage)
})
} catch (error) {
console.log(error)
}
}
// searchQuery()
searchButton.addEventListener("click", searchQuery)