Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 21 additions & 27 deletions app.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="app.css" />
<title>Gallery</title>
</head>
<body>
<div>
<h1>
Gallery
</h1>
<p>Share all your photos right here</p>
</div>
<!-- Photo grid start -->
<div id="app"></div>

<!-- HINT in this comment you can see
<head>
<link rel="stylesheet" type="text/css" href="app.css" />
<title>Gallery</title>
</head>

<body>
<div>
<h1>
Gallery
</h1>
<p>Share all your photos right here</p>
</div>
<!-- Photo grid start -->
<div id="app"></div>

<!-- HINT in this comment you can see
the future behavior of the gallery -->

<!-- <div class="row">
<div class="column">
<img src="https://source.unsplash.com/P44RIGl9V54" />
<img src="https://source.unsplash.com/P44RIGl9V54" />
<img src="https://source.unsplash.com/P44RIGl9V54" />
<img src="https://source.unsplash.com/P44RIGl9V54" />
<img src="https://source.unsplash.com/P44RIGl9V54" />
</div>
</div> -->
<!-- Photo grid finish -->
<script src="app.js"></script>
</body>
</html>
<!-- Photo grid finish -->
<script src="app.js"></script>
</body>

</html>
31 changes: 31 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,34 @@ fetch('url').then(ResolveFuntion, RejectFuntion)
*/

const app = document.querySelector("#app");
let divR = document.createElement("div");
divR.className = "row";
app.appendChild(divR);

fetch(URL)
.then((response) => {
if (response.status >= 200 && response.status <= 299) {
return response.json();
} else {
throw new Error(
`Encountered something unexpected: ${response.status} ${response.statusText}`
);
}
})
.then((data) => {
data.forEach(item => {
let divC = document.createElement("div");
divC.className = "column";
let img = document.createElement("img");
img.src = item.url;
let p = document.createElement("p");
p.textContent = item.author + " - " + item.title;
divC.appendChild(img);
divC.appendChild(p);
divR.appendChild(divC);
});
})
.catch((error) => {
// Handle the error
console.log(error);
});