-
Notifications
You must be signed in to change notification settings - Fork 1
/
the-movie.html
148 lines (120 loc) · 3.5 KB
/
the-movie.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html>
<head>
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>The Movie Test Git Pull Request</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 16px;
}
h1 {
display: flex;
justify-content: center;
}
.movie-list-container {
width: 100%;
@media only screen and (max-width: 425px) {
width: 400px;
height: auto;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
}
#movie-list {
display: flex;
gap: 20px;
flex-wrap: wrap;
@media only screen and (max-width: 425px) {
flex-wrap: nowrap;
}
}
.movie {
max-width: 300px;
background-color: #f9f9f9;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.movie img {
width: 100%;
height: auto;
object-fit: cover;
}
.movie-content {
padding: 10px;
}
.movie-title {
font-size: 1.2rem;
font-weight: bold;
margin: 5px 0;
}
.movie-rating {
margin-bottom: 5px;
}
.movie-description {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
</style>
</head>
<body>
<h1>Movie Recommendations</h1>
<div class="movie-list-container">
<div id="movie-list"></div>
</div>
</body>
#tambahan saya
<script>
const accessTokenAuth = 'My Acces Token Auth in TMDB';
const apiUrl = 'https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&language=en-US&page=1&sort_by=popularity.desc';
fetch(apiUrl,
{
headers: {
accept: 'aplication/json',
Authorization: `Bearer ${accessTokenAuth}`
}
})
.then(response => response.json())
.then(data => {
// Parse JSON response
const movies = data.results;
// Get the container to append movies
const movieListContainer = document.getElementById('movie-list');
// Iterate over movies and create HTML elements
movies.forEach(movie => {
// Create elements
const movieDiv = document.createElement('div');
movieDiv.classList.add('movie');
const img = document.createElement('img');
img.src = `https://image.tmdb.org/t/p/w300${movie.poster_path}`;
const contentDiv = document.createElement('div');
contentDiv.classList.add('movie-content');
const title = document.createElement('h2');
title.classList.add('movie-title');
title.textContent = movie.title;
const rating = document.createElement('p');
rating.classList.add('movie-rating');
rating.textContent = `Rating: ${movie.vote_average}`;
const description = document.createElement('p');
description.classList.add('movie-description');
description.textContent = movie.overview;
const date = document.createElement('p');
date.classList.add('movie-date');
date.textContent = `Movie Release Date: ${movie.release_date}`;
// Append elements to movieDiv
contentDiv.appendChild(title);
contentDiv.appendChild(rating);
contentDiv.appendChild(description);
contentDiv.appendChild(date);
movieDiv.appendChild(img);
movieDiv.appendChild(contentDiv);
// Append movieDiv to container
movieListContainer.appendChild(movieDiv);
});
})
.catch(error => console.log('something went wrong'));
</script>
</html>