From dec52f11b11036da6a2872b0206b4eea53699daf Mon Sep 17 00:00:00 2001 From: Alina Sofragiu Date: Sat, 15 Aug 2026 10:31:59 +0100 Subject: [PATCH] Add initial files for Programmer Humour feature --- fetch/programmer-humour/index.html | 15 +++++++++++++++ fetch/programmer-humour/script.js | 25 +++++++++++++++++++++++++ fetch/programmer-humour/style.css | 10 ++++++++++ 3 files changed, 50 insertions(+) create mode 100644 fetch/programmer-humour/index.html create mode 100644 fetch/programmer-humour/script.js create mode 100644 fetch/programmer-humour/style.css diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html new file mode 100644 index 000000000..1f2ab4550 --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,15 @@ + + + + + + Programmer Humour + + + +

Programmer Humour

+
+ + + + diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js new file mode 100644 index 000000000..f567d6a68 --- /dev/null +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,25 @@ +function getLatestComic() { + fetch("https://xkcd.now.sh/?comic=latest") + .then(function (response) { + if (!response.ok) { + throw new Error("Failed to fetch comic"); + } + return response.json(); + }) + .then(function (data) { + console.log(data); + + const comic = document.getElementById("comic"); + const image = document.createElement("img"); + + image.src = data.img; + image.alt = data.title; + + comic.appendChild(image); + }) + .catch(function (error) { + console.error("Error:", error); + }); +} + +getLatestComic(); diff --git a/fetch/programmer-humour/style.css b/fetch/programmer-humour/style.css new file mode 100644 index 000000000..f55e8258f --- /dev/null +++ b/fetch/programmer-humour/style.css @@ -0,0 +1,10 @@ +body { + font-family: Arial, sans-serif; + text-align: center; + margin: 40px; +} + +img { + max-width: 100%; + height: auto; +}