From 5b8b6d2ae49684fc9dc5ab97154b02bb55ec0594 Mon Sep 17 00:00:00 2001 From: Asanda Date: Tue, 29 Sep 2026 23:38:59 +0200 Subject: [PATCH] Add programmer humour fetch exercise --- fetch/programmer-humour/index.html | 17 +++++++++++++++++ fetch/programmer-humour/script.js | 26 ++++++++++++++++++++++++++ fetch/programmer-humour/style.css | 8 ++++++++ 3 files changed, 51 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..3910a58fe --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,17 @@ + + + + + + Programmer Humour + + + + +

Programmer Humour

+ +
+ + + + \ No newline at end of file diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js new file mode 100644 index 000000000..a83be553e --- /dev/null +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,26 @@ +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..101484fcb --- /dev/null +++ b/fetch/programmer-humour/style.css @@ -0,0 +1,8 @@ +body { + font-family: Arial, sans-serif; + text-align: center; +} + +#comic img { + max-width: 100%; +} \ No newline at end of file