-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
73 lines (62 loc) · 1.94 KB
/
app.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// fetch('https://api.cryptonator.com/api/ticker/btc-usd')
// .then(res => {
// console.log("RESPONSE, waiting to parse...", res)
// return res.json()
// })
// .then(data => {
// console.log("Data parsed");
// console.log(data.ticker.price)
// })
// .catch(e => {
// console.log("Oh no, error", e)
// })
// const fetchBitcoinPrice = async () => {
// try {
// const res = await fetch('https://api.cryptonator.com/api/ticker/btc-usd');
// console.log(res)
// const data = await res.json()
// console.log(data.ticker.price)
// } catch (e) {
// console.log("Something went wrong...", e)
// }
// }
// axios.get('https://api.cryptonator.com/api/ticker/btc-usd')
// .then(res => {
// console.log(res.data.ticker.price)
// })
// .catch(e => {
// console.log("Oh no, error", e)
// })
// const fetchBTCPrice = async () => {
// try {
// const res = await axios.get('https://api.cryptonator.com/api/ticker/btc-usd')
// console.log(res.data.ticker.price)
// } catch (e) {
// console.log("Error", e)
// }
// }
const jokes = document.querySelector('#jokes');
const button = document.querySelector("button");
const addNewJoke = async () => {
const jokeText = await dadJoke();
const newLI = document.createElement('LI');
newLI.append(jokeText);
jokes.append(newLI);
}
button.addEventListener('click', () => {
let numberInput = document.querySelector("input");
let number = parseInt(numberInput.value) | 1;
for (i = 0; i < number; i++) {
addNewJoke();
}
numberInput.value = "";
})
const dadJoke = async () => {
try {
const config = { headers: { Accept: 'application/json' } };
const res = await axios.get('https://icanhazdadjoke.com/', config);
return res.data.joke;
} catch (e) {
return "No jokes available, sorry."
}
}