-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.js
49 lines (28 loc) · 1.06 KB
/
search.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
37
38
39
40
41
42
43
44
45
46
47
48
49
const container = document.querySelector(".card-container"),
reasultHeading = document.querySelector(".heading"),
bottom = document.querySelector(".bottom");
let input = window.location.search.split('?')[1];
console.log(input);
async function getApi(name) {
const response = await fetch(`https://www.themealdb.com/api/json/v1/1/search.php?s=${name}`);
const data = await response.json();
return data;
}
function searchMeal() {
getApi(input).then(res => {
const meal = res.meals;
reasultHeading.innerHTML = `<h2>Search results for ${input} </h2>`;
if (meal === null) {
reasultHeading.innerHTML = `<h2>There are no search reasult </h2>`;
bottom.style.position = "fixed";
bottom.style.width = "100%";
bottom.style.bottom = "0";
} else {
reasultHeading.style.height = "3rem";
Meals.showReasult(meal, container);
}
}).catch(err => console.log(err));
}
document.addEventListener("DOMContentLoaded", () => {
searchMeal();
});