-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (54 loc) · 1.94 KB
/
script.js
File metadata and controls
63 lines (54 loc) · 1.94 KB
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
const movieselect = document.getElementById("movie");
const button = document.getElementById("submit");
const moviecontainer = document.getElementById("moviecontainer")
const contentcon = document.getElementById("contentcon")
let movieID = 155;
function clearData(){
while (moviecontainer.firstChild) {
moviecontainer.removeChild(moviecontainer.firstChild);
}
while (contentcon.firstChild) {
contentcon.removeChild(contentcon.firstChild);
}
}
function getmovie(id){
axios.get(`https:api.themoviedb.org/3/movie/${id}`, {
params:{
api_key: "dd0cae472f29b3a03f6bddb5090875f0",
append_to_response: "videos",
}
}
).then((movieData) => {
console.log(movieData);
const img = document.createElement('img');
const a = document.createElement('a');
const p = document.createElement('p');
const iframe = document.createElement('iframe');
const trailers = movieData.data.videos.results.filter((trailer) => trailer.type === "Trailer");
iframe.src = `https:www.youtube.com/embed/${trailers.at(0).key}`;
img.src = `https:image.tmdb.org/t/p/w500${movieData.data.poster_path}`;
a.innerHTML = `${movieData.data.title}`;
p.innerHTML = `Release date: ${movieData.data.release_date} <br>
Popularity: ${movieData.data.popularity} <br>
Status: ${movieData.data.status} <br>
Taglines: ${movieData.data.tagline} <br>
Overview of the movie: ${movieData.data.overview} <br>
Movie id: ${movieData.data.id} <br>
Movie's Homepage Link: ${movieData.data.homepage} <br>`;
moviecontainer.append(a);
contentcon.append(p);
moviecontainer.append(img);
moviecontainer.append(iframe);
}
)};
movieselect.addEventListener("click", () => {
if(button.click){
movieID = movieselect.value;
}
})
button.addEventListener("click", () => {
if(button.click){
clearData();
getmovie(movieID);
}
})