Design comparison
SolutionDesign
Solution retrospective
I added the function to copy the advice to clipboard
Community feedback
- @fazzaamiarsoPosted over 2 years ago
Hello Kaio! Nice and clean solution!
I have some error handling tips for you.
onst rollDice = function () { fetch(`https://api.adviceslip.com/advice`) .then((res) => { if (!res.ok) throw new Error('There is something wrong! Please try again!'); // throw and stop function execution return res.json(); }) .then((data) => { adviceParagraph.textContent = data.slip.advice; }).catch((error) => { adviceParagraph.textContent = error.message; //catch the error here }) };
I hope it helps! Cheers!
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