-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
64 lines (45 loc) · 1.67 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const APIURL ="https://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=04c35731a5ee918f014970082a0088b1&page=1";
const IMGPATH = "https://image.tmdb.org/t/p/w1280";
const SEARCHAPI ="https://api.themoviedb.org/3/search/movie?&api_key=04c35731a5ee918f014970082a0088b1&query=";
const cardNew = document.querySelector("#card");
async function getMovies(api) {
const response = await fetch(api);
const data = await response.json();
showMovie(data.results);
}
// calling getmovies function
getMovies(APIURL);
// showmovies function
const showMovie = (data) => {
// every time it empty
cardNew.innerHTML = "";
// applying for each method in all object
data.forEach((items) => {
//creating div
const box = document.createElement("div");
// adding class list
box.classList.add("movieCard");
box.innerHTML = `
<img src="${IMGPATH + items.poster_path}" alt=""/>
<div class="overlay">
<div class="header">
<h2>${items.original_title}</h2>
<span>${items.vote_average}</span>
</div>
<h3>Movie Overview:</h3>
<p>${items.overview}
</p>
</div>`;
//adding created child in card div
cardNew.appendChild(box);
});
};
// adding event listner on search input
document.querySelector("#search").addEventListener("keyup", function (event) {
if (event.target.value != "") {
// passing seacrh api
getMovies(SEARCHAPI + event.target.value);
} else {
getMovies(APIURL);
}
});