Ali Akbar Qasimi
@Ali-Akbar-QasimiAll comments
- @HamidQasimi90Submitted about 2 years ago@Ali-Akbar-QasimiPosted about 2 years ago
Hello my dear brother,
This is very good I am proud of you.
Marked as helpful0 - @ehsanqasimiSubmitted about 2 years ago@Ali-Akbar-QasimiPosted about 2 years ago
very good. This is a very hard challenge. It is wonderful. Try writing cleaner code not trowing a bunch of code. It is not based on the amount of code you write it is based what you code does. anyway you did your best. mashallah my brother.
0 - @johnrookie-coderSubmitted over 2 years ago
Hi guys, I'm new to JavaScript so I would like to ask, Is there any other way to fetch new advice without reloading the page? Anyway, feel free to suggest anything from the design and the javascript part. Thanks and have a great day!
@Ali-Akbar-QasimiPosted over 2 years agofirst of all you did a great work
you can make a function that fetch the advice and on the dice listen for a click and run the function that fetch the advice , that way you are not suppose to reload the page , and at the first line of your code you can call that function so that the advice will be fetched at the first also.
getNewAdvice()
let dice = document.querySelector('.dice') let header = document.querySelector('.header') let advice = document.querySelector('.advice')
dice.addEventListener('click',()=>{ getNewAdvice() })
async function getNewAdvice(){ let response = await fetch('https://api.adviceslip.com/advice') let data = await response.json() console.log(data) header.textContent = 'Advice #' + data.slip.id advice.textContent = data.slip.advice }
this is how i made it, hope it helped you.
0