forked from keeezy/Al-Dente
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (28 loc) · 820 Bytes
/
app.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
35
36
//functions to get data from the api
var recipes = {
fetchRecipes: function(recipe){
console.log(recipe)
fetch(
"https://api.edamam.com/api/recipes/v2?type=public&q=" +
recipe +
"&app_id=69cf7082&app_key=844db0530aecb5987dfe95007e77dfa9"
).then((response) => {
if (!response.ok) {
throw new Error("No recipe found");
}
return response.json();
}) .then((data) => {
this.displayResults(data).hits;
console.log(data)
})
console.log(recipe)
},
//search button function
search: function () {
this.fetchRecipes(document.querySelector(".search-bar").value);
},
};
//Event listener for search button
document.querySelector("#button-search").addEventListener("click", function () {
recipes.search();
});