-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (40 loc) · 932 Bytes
/
index.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
async function searchMovie() {
try {
let movie = document.getElementById("query").value;
let res = await fetch(
`https://www.omdbapi.com/?apikey="enter your API key"=${movie}`
);
let data = await res.json();
// console.log(data.Search);
return data.Search;
} catch (err) {
console.log(err);
}
}
async function main() {
let data = await searchMovie();
if (data === undefined) {
return;
}
appendData(data);
console.log(data);
}
let moviesDiv = document.getElementById("movies");
function appendData(data) {
moviesDiv.innerHTML = null;
data.map(function (el) {
let p = document.createElement("p");
p.innerText = el.Title;
moviesDiv.append(p);
});
}
//debounce code
let timerId;
function debounce() {
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(function () {
main();
}, 1000);
}