From 3b6d02e3fd32aaa76123095b9af29ddaa866aba1 Mon Sep 17 00:00:00 2001 From: Mohsen Zamani Date: Thu, 5 Feb 2026 00:41:46 +0000 Subject: [PATCH 1/2] Complete feature/xkcd --- fetch/programmer-humour/index.html | 13 +++++++++++++ fetch/programmer-humour/script.js | 14 ++++++++++++++ fetch/programmer-humour/style.css | 7 +++++++ 3 files changed, 34 insertions(+) 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..521ca7ad --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,13 @@ + + + + + + xkcd + + + + + + + diff --git a/fetch/programmer-humour/script.js b/fetch/programmer-humour/script.js new file mode 100644 index 00000000..6d13d99e --- /dev/null +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,14 @@ +const fetchData = async () => { + const url = `https://xkcd.now.sh/?comic=latest`; + try { + const response = await fetch(url); + const data = await response.json(); + const imageEl = document.getElementById("image"); + imageEl.src = data.img; + imageEl.alt = data.alt; + } catch (error) { + console.log(`Error: ${error}`); + } +}; + +fetchData(); diff --git a/fetch/programmer-humour/style.css b/fetch/programmer-humour/style.css new file mode 100644 index 00000000..0745032e --- /dev/null +++ b/fetch/programmer-humour/style.css @@ -0,0 +1,7 @@ +body { + height: 100vh; + display: flex; + justify-content: center; + align-items: center; + background-color: rgb(117, 67, 5); +} From 08bf2d138502c50d287aff291cd87aeac6433d46 Mon Sep 17 00:00:00 2001 From: Mohsen Zamani Date: Fri, 13 Feb 2026 00:52:22 +0000 Subject: [PATCH 2/2] Apply changes commented by reviewer --- 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 6d13d99e..fd6dc7e9 100644 --- a/fetch/programmer-humour/script.js +++ b/fetch/programmer-humour/script.js @@ -2,12 +2,15 @@ const fetchData = async () => { const url = `https://xkcd.now.sh/?comic=latest`; try { const response = await fetch(url); + + if (!response.ok) throw new Error(`HTTP error: ${response.status}`); + const data = await response.json(); const imageEl = document.getElementById("image"); imageEl.src = data.img; imageEl.alt = data.alt; } catch (error) { - console.log(`Error: ${error}`); + console.log(`Failed to fetch: ${error}`); } };