Design comparison
Solution retrospective
Hi everyone, This was a fun challenge. I tried the Fetch API in a project (that's not a tutorial) for the first time. The app seems to work fine on Chrome and Edge, but doesn't seem to work on firefox. Would appreciate any insight on why that may happen, and any other feedback on how to improve the app. Thank you :)
Community feedback
- @RoksolanaVeresPosted about 1 year ago
Hi, Julie! While doing this challenge I had the same problem with Firefox: the app simply did not generate any new quotes. Fortunately, one great person gave me valuable tips on how to overcome the problem, so I'm going to share some of his ideas with you.
To begin with, the problem seems to be in the very API. For some reason, it takes much more time to produce a new quote in Firefox, than in Chrome and other browsers. To get around this issue you can generate the random advice ids manually by using Math.random().
Here how it looks like: the total number of advices in the api ranges from 1 to 224, so you can do this by calling: https://api.adviceslip.com/advice/177 , where 177 is the advice (a random number between 1 and 224)
Then every time you need to fetch a new advice you can do it in this way:
const ADVICE_BASE_API = "https://api.adviceslip.com/advice"; async function generateAdvice() { const id = generateRandomId(); // your function that generates a random id const res = await fetch(`${ADVICE_BASE_API}/{$id}`) const advice = await res.json(); return advice.slip; }
Hope that you got the general idea, but if my explanation is not clear enough, feel free to ask some additional questions or have a look at my solution to the same challenge.
Happy coding 🙂
UPDATE: While looking through the solutions of other people, I found a simpler way to make this app work in Firefox. You just have to modify the fetch method in this way:
fetch("https://api.adviceslip.com/advice", { method: "GET", mode: "cors", cache: "no-cache", })
Marked as helpful0
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