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

Responsive, API

@olena-ostapenko

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 decided to add it to make the bone spin. while the library is loading.maybe there is a simpler solution?

Community feedback

P
Jacksen 350

@jacksen30

Posted

Hello @olena-ostapenko,

Your solution looks great,

A couple of small suggestions I have are, Instead of using an anchor tag for the button, it would be more semantically correct to use a button element. For instance:

<button class="decor-circle" aria-label="Update Quote">
    <img class="dice" src="./images/icon-dice.svg" alt="">
</button>

For the animation it could be simplified in the CSS like so:

/* Defines the rotation animation */
@keyframes rotate {
  0% {
      transform: rotate(0deg);
  }
  100% {
      transform: rotate(360deg);
  }
}

It might be beneficial to initiate the rotation at the beginning of your function and halt it upon either the successful retrieval of data or in the event of an error. This adjustment ensures the animation runs only while data is being fetched, rather than for a predetermined duration. This was the solution that I came to:

function retriveQuote () {
    // Start the rotation animation
    button.style.animation = "rotate 1s linear infinite";

    fetch('https://api.adviceslip.com/advice')
        .then(response => {
            if (!response.ok) {
                throw new Error("Network response was not ok")
            }
            return response.json();
        })
        .then(data => {
            dynamicIdContainer.innerHTML = `Advice # ${data.slip.id}`;
            dynamicQuoteContainer.innerHTML = `&ldquo;${data.slip.advice}&rdquo;`;
            // Stop the rotation animation when data is received
            button.style.animation = 'none';
        })
        .catch(error => {
            console.log('There was a problem with the fetch operation:', error.message);
            // Stop the rotation animation upon a fetch error
            button.style.animation = 'none';
        });
    };

retriveQuote();

I hope you find these suggestions helpful! Let me know if you have any questions or if there's anything else I can assist with.

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