Fazza Razaq Amiarso• 2,340
@fazzaamiarso
Posted
Hello Kaio! Nice and clean solution!
I have some error handling tips for you.
onst rollDice = function () {
fetch(`https://api.adviceslip.com/advice`)
.then((res) => {
if (!res.ok) throw new Error('There is something wrong! Please try again!'); // throw and stop function execution
return res.json();
})
.then((data) => {
adviceParagraph.textContent = data.slip.advice;
}).catch((error) => {
adviceParagraph.textContent = error.message; //catch the error here
})
};
I hope it helps! Cheers!
Marked as helpful
1
Kaio• 460
@kaiohnr
Posted
@fazzaamiarso Thanks!! :D
0