Design comparison
Community feedback
- @Adel-HarratPosted over 1 year ago
Hello and congratulations on completing this challenge! 🎉
Great job on creating a UI that is pretty identical. It seems you have encountered a small bug where clicking on the dice button does not fetch new advice. This issue is due to the server and not your code.
To fix this problem, you can modify the API fetch request. Instead of using:
// Fetching the random advice data fetch("https://api.adviceslip.com/advice")
You can use the following code:
// Fetching the random advice data fetch(`https://api.adviceslip.com/advice?t=${Math.random()}`)
By appending
?t=${Math.random()}
to the API URL, you add a random query parameter, which helps bypass any caching mechanisms on the server side. This ensures that each request is treated as unique, and you receive new advice every time you click the dice button.I hope this helps! Let me know if you have any further questions. 👋
Marked as helpful0@dscorzoniPosted over 1 year agoHi @Adel-Harrat , thanks for the advice! For some reason, it's working for me when I access directly from github pages: https://dscorzoni.github.io/project-advice-generator/. When I click the dice button, it's always showing me a random advice.
By the specification of API, the endpoint https://api.adviceslip.com/advice should return a random advice, so I'm not sure why it's not changing for you.
Thanks!
0@Adel-HarratPosted over 1 year ago@dscorzoni because the server caches the advice !
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