diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html new file mode 100644 index 000000000..a5dca2b33 --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,20 @@ + + + + + + + Programmer Humour + + + + + + +

Latest XKCD Comic

+ +
+ + + + \ 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..0d1ba321e --- /dev/null +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,24 @@ +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 image = document.createElement("img"); + + image.src = data.img; + image.alt = data.alt; + + const container = document.querySelector("#comic-container"); + + container.appendChild(image); + }) + .catch(function(error) { + console.error("Error:", error); + }); \ No newline at end of file diff --git a/fetch/programmer-humour/style.css b/fetch/programmer-humour/style.css new file mode 100644 index 000000000..429941e50 --- /dev/null +++ b/fetch/programmer-humour/style.css @@ -0,0 +1,9 @@ +body { + font-family: Arial, sans-serif; + text-align: center; + margin: 40px; +} + +#comic-container { + margin-top: 20px; +} \ No newline at end of file