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

API card using html scss and JS

Ciceron 940

@MarcusTuliusCiceron

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


For some reason I can't manage to make the code work on the button click but on page refresh it seems to work. Does anyone have an idea of what I'm missing there ? first time working with API and promises to, it was quite complicate to understand how to make things work

Community feedback

@zougari47

Posted

Hi there👋,

I have faced this problem before, you need to clear cache every time you use fetch API

This is the solution for your code

function getAdvice(){
    fetch('https://api.adviceslip.com/advice', {
  cache: 'no-cache'
}).then(response =>{
        return response.json();
    }).then(adviceData =>{
        const adviceObj = adviceData.slip;
        resDiv.innerHTML = `<p>${adviceObj.advice}</p>`;
        resTitle.innerHTML = `ADVICE #${adviceObj.id}`;
        console.log(adviceObj.advice);
    }).catch(error =>{
        console.log(error);
    })
}
``

Marked as helpful

0

Ciceron 940

@MarcusTuliusCiceron

Posted

@zougari47 :D yeah that works, thank you very much for info

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