diff --git a/fetch/programmer-humour/index.html b/fetch/programmer-humour/index.html new file mode 100644 index 0000000..7739dd8 --- /dev/null +++ b/fetch/programmer-humour/index.html @@ -0,0 +1,21 @@ + + + + + + + Latest XKCD Comic + + + + +
+

Latest XKCD Comic

+
+

Loading...

+
+
+ + + + \ 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 0000000..8527f46 --- /dev/null +++ b/fetch/programmer-humour/script.js @@ -0,0 +1,25 @@ +async function fetchLatestComic() { + const apiUrl = 'https://xkcd.now.sh/?comic=latest'; + const comicContainer = document.getElementById('comic-container'); + + try { + const response = await fetch(apiUrl); + + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + + const data = await response.json(); + console.log(data); + + comicContainer.innerHTML = ` + ${data.alt} +

${data.title}

+ `; + } catch (error) { + console.error('Error fetching the comic:', error); + comicContainer.innerHTML = '

Sorry, there was an error loading the comic. Please try again later.

'; + } +} + +fetchLatestComic(); \ No newline at end of file diff --git a/fetch/programmer-humour/styles.css b/fetch/programmer-humour/styles.css new file mode 100644 index 0000000..08ea56f --- /dev/null +++ b/fetch/programmer-humour/styles.css @@ -0,0 +1,39 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + height: 100vh; + display: flex; + justify-content: center; + align-items: center; + background-color: #FF3CAC; + background-image: linear-gradient(225deg, #FF3CAC 0%, #784BA0 50%, #2B86C5 100%); + background-size: cover; + color: black; +} + + + +.card { + background: rgba(255, 255, 255, 0.6); + border-radius: 15px; + box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2); + padding: 20px 40px; + text-align: center; + max-width: 500px; + width: 90%; +} + +#comic-container { + margin-top: 20px; +} + +#comic-container img { + max-width: 100%; + height: auto; +} + +#comic-container p { + font-size: 1.1rem; + color: black; +} \ No newline at end of file