Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Advice Generator App

@dscorzoni

Desktop design screenshot for the Advice generator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
  • API
2junior
View challenge

Design comparison


SolutionDesign

Community feedback

Adel 820

@Adel-Harrat

Posted

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 helpful

0

@dscorzoni

Posted

Hi @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 820

@Adel-Harrat

Posted

@dscorzoni because the server caches the advice !

Marked as helpful

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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