From 84e64404880fae4bdd24798e9b2491eab666bded Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Mon, 13 Apr 2026 00:12:18 +0100 Subject: [PATCH 1/6] create initial HTML, CSS and JS files --- fetch/programmer-humour/index.html | 0 fetch/programmer-humour/script.js | 0 fetch/programmer-humour/style.css | 0 3 files changed, 0 insertions(+), 0 deletions(-) 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 00000000..e69de29b diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js new file mode 100644 index 00000000..e69de29b diff --git a/fetch/programmer-humour/style.css b/fetch/programmer-humour/style.css new file mode 100644 index 00000000..e69de29b From c5860f4bd2a79c81f73e9a76fe49e81a757b21df Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Mon, 13 Apr 2026 18:58:18 +0100 Subject: [PATCH 2/6] fetch data; log to console --- fetch/programmer-humour/index.html | 24 ++++++++++++++++++++++++ fetch/programmer-humour/script.js | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html index e69de29b..b47d6012 100644 --- a/fetch/programmer-humour/index.html +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,24 @@ + + + + + + Document + + + + + + + + + Document + + + + + + + + + \ No newline at end of file diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js index e69de29b..a13ac8d8 100644 --- a/fetch/programmer-humour/script.js +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,4 @@ +const url = "https://xkcd.now.sh/?comic=latest"; +fetch(url) + .then((response) => response.json()) + .then((data) => console.log(data)); \ No newline at end of file From d22ef514f377d56f2b2f966ee51d36e63a8cc03f Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Mon, 13 Apr 2026 19:02:45 +0100 Subject: [PATCH 3/6] removed typo --- fetch/programmer-humour/index.html | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html index b47d6012..1577f1b3 100644 --- a/fetch/programmer-humour/index.html +++ b/fetch/programmer-humour/index.html @@ -1,24 +1,17 @@ + - Document + fetch data - - - - - - Document - - - - + + - - - \ No newline at end of file + + + From 5a22a705e463b9fa8571ee30b48387e273b6811a Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Mon, 13 Apr 2026 19:20:37 +0100 Subject: [PATCH 4/6] render image to DOM --- fetch/programmer-humour/index.html | 2 +- fetch/programmer-humour/script.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html index 1577f1b3..8c0660f8 100644 --- a/fetch/programmer-humour/index.html +++ b/fetch/programmer-humour/index.html @@ -8,7 +8,7 @@ - + diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js index a13ac8d8..73f16a71 100644 --- a/fetch/programmer-humour/script.js +++ b/fetch/programmer-humour/script.js @@ -1,4 +1,6 @@ const url = "https://xkcd.now.sh/?comic=latest"; +const image = document.getElementById("image"); + fetch(url) .then((response) => response.json()) - .then((data) => console.log(data)); \ No newline at end of file + .then((data) => image.src = data.img); From 901b1e6af13dd563bacc2d8e69502a98c28f72f4 Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Mon, 13 Apr 2026 19:35:21 +0100 Subject: [PATCH 5/6] Incorporate error handling --- fetch/programmer-humour/script.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js index 73f16a71..54885f74 100644 --- a/fetch/programmer-humour/script.js +++ b/fetch/programmer-humour/script.js @@ -3,4 +3,7 @@ const image = document.getElementById("image"); fetch(url) .then((response) => response.json()) - .then((data) => image.src = data.img); + .then((data) => image.src = data.img) + .catch((error) => { + throw(error) + }); \ No newline at end of file From 384f4f01884d2c56d55963db4a7dc3cee8724bcb Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Mon, 13 Apr 2026 19:37:01 +0100 Subject: [PATCH 6/6] Incorporate error handling --- fetch/programmer-humour/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js index 54885f74..341b0ae4 100644 --- a/fetch/programmer-humour/script.js +++ b/fetch/programmer-humour/script.js @@ -5,5 +5,5 @@ fetch(url) .then((response) => response.json()) .then((data) => image.src = data.img) .catch((error) => { - throw(error) + console.log(error) }); \ No newline at end of file