Design comparison
Solution retrospective
my async function is fetching the advice from the api only on the first button click, how can i solve this, i've commented the code below in my app.js
Community feedback
- @remyboirePosted over 2 years ago
Hi, it looks like the browser keep the data in cache, change
fetch(advice_url)
byfetch(advice_url, { cache: "no-cache" })
and it will work ! More info here1 - @pleasantvikPosted over 2 years ago
I look through your async function.
You will have to attach the event to the dice again and call it on the click
async function getAdvice(url) { const response = await fetch(url); let data = await response.json();
id.innerHTML =
# ${data.slip.id}
; adviceContent.innerHTML = data.slip.advice; }dice.addEventListener("click", function () { getAdvice(advice_url); });
0
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