cheg• 380
@chegx
Posted
Hi @peterbujaky!
In Firefox browser the button doesn't work. You can add an option {cache: "no-cache"}
to make it return a new piece of advice.
fetch("https://api.adviceslip.com/advice", {cache: "no-cache"})
.then(res => res.json())
.then (data => {
const advice = data.slip.advice;
const id = data.slip.id;
document.getElementById("adviceText").innerHTML = `"${advice}"`;
document.getElementById("adviceID").innerHTML = `ADVICE #${id}`;
})
document.getElementById("button").addEventListener("click", () => {
fetch("https://api.adviceslip.com/advice", {cache: "no-cache"})
.then(res => res.json())
.then(data => {
const advice = data.slip.advice;
const id = data.slip.id;
document.getElementById("adviceText").innerHTML = `"${advice}"`;
document.getElementById("adviceID").innerHTML = `ADVICE #${id}`;
})
})
Marked as helpful
1
Peter Bujaky• 110
@peterbujaky
Posted
@chegx Thanks for the valuable info.
1