@HamidQasimi90
Submitted
@Ali-Akbar-Qasimi
@HamidQasimi90
Submitted
@Ali-Akbar-Qasimi
Posted
Hello my dear brother,
This is very good I am proud of you.
Marked as helpful
@ehsanqasimi
Submitted
@Ali-Akbar-Qasimi
Posted
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.
@johnrookie-coder
Submitted
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-Qasimi
Posted
first 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.