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
21 changes: 21 additions & 0 deletions fetch/programmer-humour/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">

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

<body>
<div class="card">
<h1>Latest XKCD Comic</h1>
<div id="comic-container">
<p>Loading...</p>
</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 fetchLatestComic() {
const apiUrl = 'https://xkcd.now.sh/?comic=latest';
const comicContainer = document.getElementById('comic-container');

try {
const response = await fetch(apiUrl);

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const data = await response.json();
console.log(data);

comicContainer.innerHTML = `
<img src="${data.img}" alt="${data.alt}">
<p>${data.title}</p>
`;
} catch (error) {
console.error('Error fetching the comic:', error);
comicContainer.innerHTML = '<p>Sorry, there was an error loading the comic. Please try again later.</p>';
}
}

fetchLatestComic();
39 changes: 39 additions & 0 deletions fetch/programmer-humour/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #FF3CAC;
background-image: linear-gradient(225deg, #FF3CAC 0%, #784BA0 50%, #2B86C5 100%);
background-size: cover;
color: black;
}



.card {
background: rgba(255, 255, 255, 0.6);
border-radius: 15px;
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
padding: 20px 40px;
text-align: center;
max-width: 500px;
width: 90%;
}

#comic-container {
margin-top: 20px;
}

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

#comic-container p {
font-size: 1.1rem;
color: black;
}