Skip to content
Closed
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
16 changes: 16 additions & 0 deletions fetch/programmer-humour/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Programmer Humour</title>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<h1>Comic</h1>
<div id="comic-container"></div>
<p id="error-message"></p>
<script src="script.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions fetch/programmer-humour/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function getComic() {
fetch("https://xkcd.now.sh/?comic=latest")
.then((res) => res.json())
.then((data) => {
console.log(data);
document.getElementById("comic-container").innerHTML =
`<img src="${data.img}">`;
})
.catch(() => {
document.getElementById("error-message").textContent =
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice error handling. It's good practice to handle errors and give users feedback when things are not working

"Error loading comic";
});
}
getComic();
20 changes: 20 additions & 0 deletions fetch/programmer-humour/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
body {
text-align: centre;
font-family: Arial, sans-serif;
}

img {
max-width: 100%;
background-color: rgb(174, 130, 217);
padding: 10%;
display: block;
}
h1{
text-align: center;
font-family: 'Courier New', Courier, monospace;
background-color: blanchedalmond;
}
img {
display: block;
margin: 0 auto;
}
Loading