Design comparison
Solution retrospective
How could I make my code more simpler and readable? Should I use async/await instead of promises in my js? How could I make my solution look more closer to the challenge solution?
Community feedback
- @Mod8124Posted over 2 years ago
Well done! you can improve your code, by doing this:
const URL = "https://api.adviceslip.com/advice' fetch(URL) .then(response => response.json()) .then(data => { const { id, advice } = data.slip adviceId.textContent = `#${id}`; adviceText.textContent = `${advice}`; }).catch(err => console.log(err.message)
you can extract that id and advice directly from the data this is called Destructuring assignment also you don't have to reload the page just call the function by default when loaded the document and called again with a click event, in the way you make your solution a spa
window.addEventListener('load', fetchAdvice) //default button.addEventListener('click', fetchAdvice); //bring new advice
Also if you wanna make your solution closer to the design you can use pixel-perfect tools : pixel
Marked as helpful0@purplehippo911Posted over 2 years agoHi @Mod8124. Thanks for the help, I really appreciate it. I´ll remember to fix it when I´ve got time. Have a good day.
0
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