forked from kokonior/Javascript-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDMuhammad
60 lines (52 loc) · 1.79 KB
/
DMuhammad
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
import axios from "axios";
function main() {
const url = "http://www.omdbapi.com";
const api = "apikey=b1f3860a";
const searchElement = document.querySelector("#searchElement");
const searchButton = document.querySelector("#searchButton");
const movie = async () => {
try {
const get = await axios.get(`${url}/?${api}&s=one piece&type=movie`);
const resGet = await get.data.Search;
render(resGet);
} catch (error) {
console.log(error);
}
}
const searchMovie = async (key) => {
try {
const get = await axios.get(`${url}/?${api}&s=${key}&type=movie`);
const resGet = await get.data.Search;
render(resGet);
} catch (error) {
console.log(error);
}
}
const render = (movies) => {
const card = document.querySelector(".row");
const totalMovie = document.querySelector(".totalMovie");
card.innerHTML = "";
totalMovie.innerHTML = movies.length;
movies.forEach( movie => {
card.innerHTML += `
<div class="col">
<div class="card p-3 border bg-light h-100" style="width: 18rem;">
<img src="${movie.Poster}" class="card-img-top img-thumbnail">
<div class="card-body">
<h5 class="card-title">${movie.Title}</h5>
<p class="card-text">${movie.Year}</p>
</div>
</div>
</div>
`;
})
}
searchButton.addEventListener("click", () => {
searchMovie(searchElement.value);
searchElement.value = '';
})
document.addEventListener("DOMContentLoaded", () => {
movie();
});
};
export default main;