Skip to content

ITP-JAN-LONDON|FOROGH AGHAEIYARIJANI|MODULE-DATA-FLOWS|SPRINT3|WEEK3|PROGRAMMER HUMOUR|completed files #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions fetch/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Latest XKCD Comic</title>
<link rel="stylesheet" href="programmer-humour/style.css">
</head>
<body>
<h1>Latest XKCD Comic</h1>
<div id="comic-container"></div>
<div class="error" id="error-msg"></div>
<script src="programmer-humour/script.js" defer></script>
</body>
</html>
28 changes: 28 additions & 0 deletions fetch/programmer-humour/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const XKCD_API_URL = 'https://xkcd.now.sh/?comic=latest';

async function fetchLatestXKCD() {
try {
const response = await fetch(XKCD_API_URL);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log("Received XKCD Data:", data);

const img = document.createElement('img');
img.src = data.img;
img.alt = data.alt;

const container = document.getElementById('comic-container');
container.appendChild(img);
} catch (error) {
console.error("Error fetching XKCD comic:", error);
document.getElementById('error-msg').textContent = "Failed to load the comic. Please try again later.";
}
}

window.addEventListener("load", () => {
console.log("Page is fully loaded");
fetchLatestXKCD();
});

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 {
font-family: Arial, sans-serif;
background-color: #F4F4F4;
text-align: center;
padding: 30px;
}
h1 {
color: #333;
}
img {
max-width: 90%;
height: auto;
margin-top: 20px;
border: 1px solid #ccc;
box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.1);
}
.error {
color: red;
margin-top: 20px;
}