
Design comparison
Solution retrospective
Hi there!
I had this project styled for a week and it was waiting for me to learn using API. And I didn't, because I still do. I still have to understand Promises and Callbacks...
If you have any advices (others than on this page :D) please share with me. You can also write what you could do better.
Thank you!
Community feedback
- @0xabdulkhaliqPosted over 1 year ago
Hello there 👋. Congratulations on successfully completing the challenge! 🎉
- I have other recommendations regarding your code that I believe will be of great interest to you.
BODY MEASUREMENTS 📐:
- Use
min-height: 100vh
forbody
instead ofheight: 100vh
. Setting theheight: 100vh
may result in the component being cut off on smaller screens, such as mobile devices in landscape orientation
- For example; if we set
height: 100vh
then thebody
will have100vh
height no matter what. Even if the content spans more than100vh
of viewport.
- But if we set
min-height: 100vh
then thebody
will start at100vh
, if the content pushes thebody
beyond100vh
it will continue growing. However if you have content that takes less than100vh
it will still take100vh
in space.
.
I hope you find this helpful 😄 Above all, the solution you submitted is great !
Happy coding!
Marked as helpful1@BBualdoPosted over 1 year ago@0xAbdulKhalid Hi! I can't see the difference right now, but it surely spare me the problems with future projects 😁 I updated that small change and I will have this in mind! Thank you!
0 - @adityaphasuPosted over 1 year ago
Hello, @BBualdo!
- It's a good practice to handle errors when making API requests. To handle errors we can add a
.catch()
block to handle errors during the fetch like this:
diceButton.addEventListener('click', () => { fetch(API_ADVICE_URL) .then(res => res.json()) .then(data => { const id = data.slip.id; const advice = data.slip.advice; adviceNumber.innerHTML = `Advice #${id}`; adviceContent.innerHTML = `"${advice}"`; }) .catch(error => { console.error("An error occurred:", error); }); });
- Instead of using
innerHTML
you can usetextContent
when dealing with plain text content because it makes sure that any potential HTML tags in the data won't be treated as markup so you can rewrite the code like this:
adviceNumber.textContent = `Advice #${id}`; adviceContent.textContent = `"${advice}"`;
A brief summary of what promises and callbacks are:
- callbacks are functions you give to other functions to be called when something is done.
- promises are like assurances that something will be done. It can be in one of the 3 states that are pending(means ongoing), resolved (means its done and completed), or rejected(error is there and fail).
This was just a brief explanation.. give this video a watch by webdev simplified and i hope you will understand better from it!
Good luck!
Marked as helpful1@BBualdoPosted over 1 year ago@adityaphasu Yeah I got this done by now, and I knew the definision of callbacks and promises, I also watched his videos when preparing to code this functionality :D But thanks for your effort!
Have a nice day!
1@adityaphasuPosted over 1 year ago@BBualdo ah haha I thought it was a question but glad you know about these! I hope this worked as refresher instead then :D
1 - It's a good practice to handle errors when making API requests. To handle errors we can add a
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