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

advice generator

Kaio 460

@kaiohnr

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


I added the function to copy the advice to clipboard

Community feedback

@fazzaamiarso

Posted

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 helpful

1

Kaio 460

@kaiohnr

Posted

@fazzaamiarso Thanks!! :D

0

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