-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (24 loc) · 1.01 KB
/
script.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
var adviceBtn = document.getElementsByClassName("add-advice")[0];
var startupBtn = document.getElementsByClassName("add-startup")[0];
var searchBtn = document.getElementsByClassName("search-marvel")[0];
var container = document.querySelector('.btn-container');
var dataPack = document.getElementsByClassName('data')[0];
// button 1:
adviceBtn.addEventListener('click', async () => {
await fetch(
`https://api.adviceslip.com/advice`
).then(res => res.json())
.then(
(result) => {
container.style.display = 'none';
dataPack.innerHTML = result.slip.advice;
var backBtn = document.createElement('button', 'button');
backBtn.className = "backBtn";
backBtn.innerHTML = "Go Back";
backBtn.addEventListener('click', () => {
dataPack.innerHTML = '';
container.style.display = "flex";
});
dataPack.append(backBtn);
});
});