Design comparison
SolutionDesign
Solution retrospective
Any suggestions on how to improve my code is welcome. Thanks!
Community feedback
- @chegxPosted almost 2 years ago
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 helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord