Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
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
18 changes: 18 additions & 0 deletions programmer-humour/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Abdi Comic Web</title>
<link rel="stylesheet" href="styles.css">
</head>

<body>
<div id="comic-container">
<!-- Image will be rendered here -->
</div>
<script src="script.js"></script>
</body>

</html>
31 changes: 31 additions & 0 deletions programmer-humour/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Function to fetch latest xkcd comic
async function fetchComicData() {
try {
const response = await fetch('https://xkcd.now.sh/?comic=latest');
if (!response.ok) {
throw new Error('Failed to fetch comic');
}
const data = await response.json();
return data;
} catch (error) {
console.error(error);
return null;
}
}

// Function to render comic image to DOM
async function displayComic() {
const container = document.getElementById('comic-container');
const comicData = await fetchComicData();
if (comicData && comicData.img) {
const img = document.createElement('img');
img.src = comicData.img;
img.alt = comicData.alt;
container.appendChild(img);
} else {
container.textContent = 'Failed to load comic.';
}
}

// Call displayComic function when the page loads
displayComic();
15 changes: 15 additions & 0 deletions programmer-humour/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f2f2f2;
}

img {
max-width: 100%;
height: auto;
}