-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
50 lines (38 loc) · 1.27 KB
/
app.js
File metadata and controls
50 lines (38 loc) · 1.27 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
document.addEventListener("DOMContentLoaded", () => {
/*
* fetch movies from json and create cards
*/
const url = "/movies.json"
fetch(url)
.then(res => {
if(!res.ok){
throw Error("Response was not ok: " + res.statusText);
}
return res.json();
})
.then(data => {
console.log(data);
getMovies(data.movies);
})
.catch(error => console.error("There was a problem fethcing: ", error));
function getMovies(movies){
movies.map(movie => {
const movieBox = document.querySelector(".movie-box");
const poster = document.createElement("div");
poster.className = "movie-poster";
const image = document.createElement("img");
image.className = "movie-image";
image.src = movie.poster;
const title = document.createElement("h3");
title.className = "movie-title";
title.innerText = movie.title;
const year = document.createElement("p");
year.className ="movie-year";
year.innerText = movie.year;
poster.appendChild(image);
poster.appendChild(title);
poster.appendChild(year);
movieBox.appendChild(poster);
});
}
});