Design comparison
Solution retrospective
I have a doubt, sometimes my request takes a long time to arrive, I understand that with an Async function I could solve it. But I don't know how to implement it in my solution with fetch.
Community feedback
- @lipe11Posted over 2 years ago
Hi,
Regarding your question, to change your function to an async function looks something like this
async function showQuote() { const response = await fetch(url) const json = await response.json() idAdvice.innerHTML = json.slip.id textAdvice.innerHTML = json.slip.advice }
(note there's no need to pass the data through an array, you can reference it directly from the json object)
However, making the function async won't give you greater speed, async/await is equivalent to promise/then, choosing one over the other is just a matter of syntactic preference. For me, your function worked just fine as it is.
Also note that sometimes when you click you get the same quote from cache, it takes about 2 sec to get a fresh one. I'm guessing with this one, but it might be the reason you sometimes feel a delay in the response.
Hope this is useful
Marked as helpful0 - @enggsurajPosted over 2 years ago
You can use <q><q> in place of the h5 tag for quotes to get "" double commas as per requirement in a challenge.
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