Ahmed Zougari• 270
@zougari47
Posted
Hi there👋,
you don't need to add an advice id and increment it by 1, every time the user click the button should get random advice and https://api.adviceslip.com/advice
give you random advice.
I propose this solution :
const getAdvice = () => {
fetch("https://api.adviceslip.com/advice", {
cache: 'no-cache'
})
.then((response) => response.json())
.then((data) => {
id.innerHTML = data.slip.id
content.innerHTML = '<q>'+data.slip.advice+'</q>';
});
};
dice.addEventListener('click', getAdvice)
happy coding
Marked as helpful
0
kirty• 380
@kirtymeena
Posted
@zougari47 Hi, Thanks for the feedback, I have updated the code and it works now.
0