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; +}