-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (24 loc) · 943 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const setUp = document.getElementById('setup')
const punchBtn = document.getElementById('punch-btn')
const newBtn = document.getElementById('new-btn')
const punchLine = document.getElementById('punchline')
let punchlineVar
punchBtn.addEventListener('click', getPuchLine);
newBtn.addEventListener('click', jokeGenerator);
function getPuchLine(){
punchLine.innerHTML = punchLineVar;
punchLine.classList.add('bubble')
punchBtn.classList.toggle('hidden')
newBtn.classList.toggle('hidden')
}
async function jokeGenerator(){
const jokeGenerator = await fetch('https://official-joke-api.appspot.com/jokes/programming/random')
const jokes = await jokeGenerator.json();
setUp.innerHTML = jokes[0].setup;
punchLineVar = jokes[0].punchline;
punchLine.innerHTML = "";
punchLine.classList.remove('bubble');
punchBtn.classList.toggle('hidden');
newBtn.classList.toggle('hidden');
}
jokeGenerator();