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 App (SCSS, JS/Fetch API)

@peterbujaky

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


Any suggestions on how to improve my code is welcome. Thanks!

Community feedback

cheg 380

@chegx

Posted

Hi @peterbujaky! In Firefox browser the button doesn't work. You can add an option {cache: "no-cache"} to make it return a new piece of advice.

fetch("https://api.adviceslip.com/advice", {cache: "no-cache"})
.then(res => res.json())
.then (data => {
    const advice = data.slip.advice;
    const id = data.slip.id;
    document.getElementById("adviceText").innerHTML = `"${advice}"`;
    document.getElementById("adviceID").innerHTML = `ADVICE #${id}`;
})

document.getElementById("button").addEventListener("click", () => {
    fetch("https://api.adviceslip.com/advice", {cache: "no-cache"})
    .then(res => res.json())
    .then(data => {
        const advice = data.slip.advice;
        const id = data.slip.id;
        document.getElementById("adviceText").innerHTML = `"${advice}"`;
        document.getElementById("adviceID").innerHTML = `ADVICE #${id}`;
    })
})

Marked as helpful

1

@peterbujaky

Posted

@chegx Thanks for the valuable info.

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