Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Mobile First | My Advice - Click The Dice

BBualdo 540

@BBualdo

Desktop design screenshot for the Advice generator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
  • API
2junior
View challenge

Design comparison


SolutionDesign

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

@0xabdulkhaliq

Posted

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 for body instead of height: 100vh. Setting the height: 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 the body will have 100vh height no matter what. Even if the content spans more than 100vh of viewport.
  • But if we set min-height: 100vh then the body will start at 100vh, if the content pushes the body beyond 100vh it will continue growing. However if you have content that takes less than 100vh it will still take 100vh in space.

.

I hope you find this helpful 😄 Above all, the solution you submitted is great !

Happy coding!

Marked as helpful

1

BBualdo 540

@BBualdo

Posted

@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
Boots 😺 1,590

@adityaphasu

Posted

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 use textContentwhen 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 helpful

1

BBualdo 540

@BBualdo

Posted

@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
Boots 😺 1,590

@adityaphasu

Posted

@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
BBualdo 540

@BBualdo

Posted

@adityaphasu It worked :D I appreciate!

1

Please log in to post a comment

Log in with GitHub
Discord logo

Join 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