Design comparison
SolutionDesign
Solution retrospective
This was my first time using an API. It was a lot fun and it opens up so many possibilities with what I can build now.
How does my JavaScript look? Is there anything that could be better as far as best practices go?
Community feedback
- @VaheAAPosted about 2 years ago
Due to API specifiց things, this one always returns cached response and because of that it can seem that button to request new advice does not working. To solve this, you can add to your fetch function option to not receive cached data like this.
function getAdvice() { fetch("https://api.adviceslip.com/advice", { cache: 'no-cache' }) .then(response => response.json()) .then(data => updateUI(data)) }
Also you can try to replace then/catch with async/await.
async function getAdvice () => { try { const response = await fetch('https://api.adviceslip.com/advice', { cache: 'no-cache' }); const data = await response.json(); updateUI(data) } catch (err) { alert(err.message); } };
1
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