Skip to content

Commit 7c2f29a

Browse files
committed
separate dad jokes lessons into 2 finished folders
1 parent adc4d36 commit 7c2f29a

File tree

9 files changed

+144
-0
lines changed

9 files changed

+144
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const buttonText = [
2+
'Ugh.',
3+
'🤦🏻‍♂️',
4+
'omg dad.',
5+
'you are the worst',
6+
'seriously',
7+
'stop it.',
8+
'please stop',
9+
'that was the worst one',
10+
];
11+
12+
// default export (only one per file)
13+
export default buttonText;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Dad Jokes</title>
8+
<link rel="stylesheet" href="../../base.css">
9+
<style>
10+
html {
11+
--size: 20px;
12+
}
13+
14+
.wrapper {
15+
text-align: center;
16+
}
17+
18+
.joke {
19+
font-size: 5rem;
20+
font-weight: 900;
21+
}
22+
23+
.lds-ripple {
24+
display: inline-block;
25+
position: relative;
26+
27+
width: var(--size);
28+
height: var(--size);
29+
}
30+
31+
.lds-ripple div {
32+
position: absolute;
33+
border: 4px solid white;
34+
opacity: 1;
35+
border-radius: 50%;
36+
animation: lds-ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
37+
}
38+
39+
.lds-ripple div:nth-child(2) {
40+
animation-delay: -0.5s;
41+
}
42+
43+
@keyframes lds-ripple {
44+
0% {
45+
top: calc(var(--size) / 2);
46+
left: calc(var(--size) / 2);
47+
width: 0;
48+
height: 0;
49+
opacity: 1;
50+
}
51+
52+
100% {
53+
top: 0px;
54+
left: 0px;
55+
width: calc(var(--size) * 0.9);
56+
height: calc(var(--size) * 0.9);
57+
opacity: 0;
58+
}
59+
}
60+
61+
.hidden {
62+
display: none;
63+
}
64+
</style>
65+
</head>
66+
67+
<body>
68+
<div class="wrapper app">
69+
<div class="joke">
70+
<p>Dad Jokes.</p>
71+
</div>
72+
<button class="getJoke">
73+
<span class="jokeText">Get A Joke</span>
74+
<div class="lds-ripple loader hidden">
75+
<div></div>
76+
<div></div>
77+
</div>
78+
</button>
79+
</div>
80+
81+
<script src="./jokes.js" type="module"></script>
82+
</body>
83+
84+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { handleClick } from './lib/handlers.js';
2+
import { jokeButton } from './lib/elements.js';
3+
4+
jokeButton.addEventListener('click', handleClick);
5+
6+
console.log('heyy');
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const jokeButton = document.querySelector('.getJoke');
2+
export const jokeButtonSpan = jokeButton.querySelector('.jokeText');
3+
export const jokeHolder = document.querySelector('.joke p');
4+
export const loader = document.querySelector('.loader');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { fetchJoke } from './index.js';
2+
import { loader, jokeHolder, jokeButtonSpan } from './elements.js';
3+
import { randomItemFromArray } from './utils.js';
4+
import buttonText from '../data/buttonText.js';
5+
6+
// Named export
7+
export async function handleClick() {
8+
const { joke } = await fetchJoke(loader);
9+
jokeHolder.textContent = joke;
10+
jokeButtonSpan.textContent = randomItemFromArray(
11+
buttonText,
12+
jokeButtonSpan.textContent
13+
);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Named Export (we can have lots of these)
2+
export async function fetchJoke(loader) {
3+
// turn loader on
4+
loader.classList.remove('hidden');
5+
const response = await fetch('https://icanhazdadjoke.com', {
6+
headers: {
7+
Accept: 'application/json',
8+
},
9+
});
10+
const data = await response.json();
11+
// turn the loader off
12+
loader.classList.add('hidden');
13+
return data;
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// named export
2+
export function randomItemFromArray(arr, not) {
3+
const item = arr[Math.floor(Math.random() * arr.length)];
4+
if (item === not) {
5+
console.log('Ahh we used that one last time, look again');
6+
return randomItemFromArray(arr, not);
7+
}
8+
return item;
9+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)