-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (27 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
28
29
30
31
32
33
34
35
36
// const adviceContainer =document.getElementById('advice');
// const dice = document.getElementById('dice')
// const url ="https://api.adviceslip.com/advice"
// let getAdvice = () => {
// adviceContainer.classList.remove("fade")
// fetch(url)
// .then(data => data.json())
// .then(item => {
// adviceContainer.textContent = `${item.slip}`
// adviceContainer.classList.add("fade")
// });
// }
// dice.addEventListener("click", getAdvice)
// getAdvice();
window.addEventListener("DOMContentLoaded",Fetchdata)
const adviceTitle = document.querySelector("#advice-id")
const advice=document.querySelector("#advice");
const dice = document.querySelector('#dice');
async function Fetchdata (){
const response = await fetch("https://api.adviceslip.com/advice");
const json = await response.json();
console.log(json);
adviceTitle.innerText= `Advice #${json.slip.id}`;
advice.innerText= `"${json.slip.advice}"`;
// Fetchdata();
}
dice.addEventListener("click", Fetchdata)