diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html new file mode 100644 index 00000000..8c0660f8 --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,17 @@ + + + + + + + fetch data + + + + + + + + + + diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js new file mode 100644 index 00000000..9a898681 --- /dev/null +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,12 @@ +const url = "https://xkcd.now.sh/?comic=latest"; +const image = document.getElementById("image"); + +fetch(url) + .then((response) => response.json()) + .then((data) => { + image.src = data.img; + console.log(data); + }) + .catch((error) => { + console.log(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 00000000..47b36ffd --- /dev/null +++ b/fetch/programmer-humour/style.css @@ -0,0 +1,6 @@ +body { + height: 100vh; + display: flex; + align-items: center; + justify-content: center; +}