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
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="styles.css" />
</head>
<body>
<div class="container">
<h1>Programmer Humour</h1>
<div id="comic"></div>
</div>
<script src="script.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions fetch/programmer-humour/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
async function getComic() {
try {
// Fetch the latest comic from the API
const response = await fetch("https://xkcd.now.sh/?comic=latest");
// Convert the response to JSON
const data = await response.json();
// Log the data to the console
console.log(data);

// Grab the comic container from the DOM
let comicDiv = document.getElementById("comic");
// Create an img element
let imgComic = document.createElement("img");
// Set the src of the img to the comic image URL
Comment on lines +5 to +14
Copy link
Copy Markdown

@Luro91 Luro91 Apr 11, 2026

Choose a reason for hiding this comment

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

I understand that comments can help you writing the code. It is best practice to only place comments where they are needed for understanding. The code should be self explanatory and comments should mainly explain why things are written in a specific way.

From https://mitcommlab.mit.edu/broad/commkit/coding-and-comment-style/

The most important concept here is that the code itself is the primary means of commenting and documentation.
Use comments only to add context or explain choices that cannot be expressed through thoughtful naming, structure or the context of operations.

You could write the comments during the development and then remove them before committing it. Try to use less of them over time

imgComic.src = data.img;
// Append the img to the comic container
comicDiv.appendChild(imgComic);
} catch (error) {
// Catch and log any errors
console.log(error);
}
}

// Call the function
getComic();
34 changes: 34 additions & 0 deletions fetch/programmer-humour/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background-color: #0d0d0d;
color: #00d4cc;
font-family: "Courier New", monospace;
}

.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
gap: 24px;
}

h1 {
color: #ff2d55;
font-size: 3rem;
text-transform: uppercase;
letter-spacing: 4px;
}

#comic img {
border: 3px solid #00d4cc;
border-radius: 8px;
box-shadow: 0 0 20px #00d4cc66;
max-width: 600px;
}
Loading