Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions programmer-humour/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

<link href="https://fonts.googleapis.com/css2?family=Comic+Neue:wght@300;400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
<title>xkcd webcomic</title>
</head>

<body>
<header>
<h1>xkcd</h1>
<p>Webcomic</p>
</header>
<main id="root">

</main>
<footer>
<p>Comic made by Randall Munroe from <a href="https://xkcd.com/" target="_blank"
rel="noopener noreferrer">xkcd.com</a></p>
<p>Page made by Pedro Ricciardi - <a href="https://www.linkedin.com/in/pedro-ricciardi/" target="_blank"
rel="noopener noreferrer">LinkedIn</a> and <a href="https://github.com/PERicci/" target="_blank"
rel="noopener noreferrer">GitHub</a>
</p>
</footer>

<script src="./script.js"></script>
</body>

</html>
35 changes: 35 additions & 0 deletions programmer-humour/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const api = "https://xkcd.now.sh/?comic=latest"

document.addEventListener('DOMContentLoaded', function () {
fetchComic(api);
});

function fetchComic(api) {
fetch(api)
.then((response) => response.json())
.then((lastComic) => renderPage(lastComic))
.catch((error) => showError(error));
}

function renderPage(data) {
console.log(data);
const root = document.querySelector("#root")
const html = htmlGenerator(data.title, data.img, data.alt);

root.innerHTML = html;
}

function htmlGenerator(title, imageUrl, imageAlt) {
let html = `<h2>${title}</h2>
<img src="${imageUrl}" alt="${imageAlt}">
<p>From <a href="https://xkcd.com/" target="_blank">xkcd.com</a></p>
</p>`

return html
}

function showError(error) {
console.log(error);
const root = document.querySelector("#root")
root.innerHTML = `<h2>${error}</h2>`
}
100 changes: 100 additions & 0 deletions programmer-humour/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
:root {
--page-width: 50vw;
--primary-colour: #3a7bd5;
--secondary-colour: #362db3;
--text-colour-dark: #333;
--text-colour-light: #ffffff;
--background-colour: #798b9b;
--foreground-colour: #fff;
--font-family: "Comic Neue", cursive;
--border-radius: 0.25rem;
--box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.2);
}

body, main, header, footer, div {
box-sizing: border-box;
}

h1, h2, h3, p, a {
margin: 0;
padding: 0;
}

a, a:active, a:visited {
text-decoration: none;
color: var(--secondary-colour);
}

a:hover {
font-weight: 700;
}

body {
margin: 0;
background-color: var(--background-colour);
font-family: var(--font-family);

height: 100vh;

display: grid;
grid-template-rows: auto 1fr auto;
}

header, main, footer {
width: var(--page-width);
margin: 0 auto;
}

h1 {
font-size: 5rem;
line-height: 4rem;
margin: 0;
color: var(--primary-colour);
}

h2 {
font-size: 2.5rem;
}

header {
background-color: var(--foreground-colour);
padding: 1rem 2rem;
}

main {
background-color: var(--primary-colour);
text-align: center;
padding: 2rem;

color: var(--text-colour-light);

display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

main a, main a:active, main a:visited {
color: var(--text-colour-light);
text-decoration: underline;
}

img {
padding: 1rem;
background-color: var(--foreground-colour);
border-radius: var(--border-radius);
margin: 1rem 0 0.5rem;
}

footer {
background-color: var(--foreground-colour);
padding: 0.5rem 1rem;
text-align: center;

color: var(--text-colour-dark);
font-weight: 300;
}

footer a{
color: var(--secondary-colour);
}