Advice generator, without framework
Design comparison
Solution retrospective
The button just refresh the page, for the task it work, some different ideia?
Community feedback
- @Icekid35Posted over 2 years ago
Hello there Nice work 👏👏
The reason it keeps reload is because you are calling location.reload() method another way to generate the advice without reloading is to modify your script from •{ fetch("https://api.adviceslip.com/advice").then((response) => { response.json().then((json) => {
titleAdvice.innerText = `ADVICE #${json.slip.id}`; advice.innerText = `" ${json.slip.advice}"`; }); btn.addEventListener('click', function() { window.location.reload(); }) });
}•••••••• To ••••••••••{ fetch("https://api.adviceslip.com/advice").then((response) => { response.json().then((json) => {
titleAdvice.innerText = `ADVICE #${json.slip.id}`; advice.innerText = `" ${json.slip.advice}"`; }); btn.addEventListener('click', function() { fetch("https://api.adviceslip.com/advice").then((response) => { response.json().then((json) => { titleAdvice.innerText = `ADVICE #${json.slip.id}`; advice.innerText = `" ${json.slip.advice}"`; });
})
}) });
}•••••• or you can just wrap it in another function like this ••••••••••••{ function Regenerate(){ fetch("https://api.adviceslip.com/advice").then((response) => { response.json().then((json) => {
titleAdvice.innerText = `ADVICE #${json.slip.id}`; advice.innerText = `" ${json.slip.advice}"`; });
} °°°°°°°°°°then call the function like this °°°°°° btn.onclick=Regenerate }••••••••• ALSO TO GET RID OF THE ACCESSIBILITY ISSUES WRAP ALL YOUR ELEMENT IN A MAIN TAG 😉•••••
0
Please log in to post a comment
Log in with GitHubJoin 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