IryDev• 1,580
@IryDev
Posted
Hey @KingLyrics, well done for your solution 😄
I have some advice in order to improve your solution :
- If you want your app to display advice when the page load you can call the function getQutoe
- Then when your page load you should see an advice instead of a lorem ipsum
JS :
const submitBtn = document.querySelector(".button");
const adviceId = document.getElementById('advice_id');
const advice = document.getElementById('advice')
// api https://api.adviceslip.com/advice
submitBtn.addEventListener("click", () => {
getQutoe();
});
const getQutoe = () => {
fetch("https://api.adviceslip.com/advice")
.then((response) => response.json())
.then((quotes) => {
adviceId.textContent = quotes.slip.id
advice.textContent = quotes.slip.advice
})
.catch(error =>{
console.log('Error fetching data:',error)
})
};
getQuote()
I hope you'll find this helpful, BTW your solution is great 😄
Marked as helpful
1
Ekomobong Edeme• 190
@KingLyrics
Posted
@IryDev Excellent observation! Thank you so much!
0
IryDev• 1,580
@IryDev
Posted
@KingLyrics Thank you! And no problem, don't hesitate to ask, if you have other questions
1