diff --git a/fetch/programmer-humour/fetch.js b/fetch/programmer-humour/fetch.js new file mode 100644 index 00000000..4b0a297d --- /dev/null +++ b/fetch/programmer-humour/fetch.js @@ -0,0 +1,17 @@ +"use strict"; +const imgElem = document.querySelector("img"); +const errorMessage = document.querySelector("#errorMessage"); + +const fetchData = async () => { + try { + const response = await fetch("https://xkcd.now.sh/?comic=latest"); + const data = await response.json(); + return data; + } catch (error) { + errorMessage.style.display = `contents`; + errorMessage.textContent = error; + } +}; +fetchData().then((data) => { + imgElem.setAttribute("src", data.img); +}); diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html new file mode 100644 index 00000000..5eced904 --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,14 @@ + + + + + + humour + + + + +
+ + + diff --git a/fetch/programmer-humour/styles.css b/fetch/programmer-humour/styles.css new file mode 100644 index 00000000..dfe73aae --- /dev/null +++ b/fetch/programmer-humour/styles.css @@ -0,0 +1,9 @@ +body { + display: flex; + justify-content: center; + align-items: center; +} +#funnyPicture { + margin: auto; + margin-top: 30vh; +}