I'm currently integrating the Advice Slip API into my project. I am experiencing an issue when trying to store the JSON data in a variable like so:
let advice;
fetch("https://api.adviceslip.com/advice").then(response => response.json()).then(data => advice = data);
Upon executing this code, I encounter an error as mentioned. However, if I modify
.then(data => advice = data)
to
.then(console.log)
I am able to see the advice object logged in the console. Nevertheless, I require the ability to save this advice in a variable for use on my website rather than solely logging it.
Therefore, I need to devise a solution that allows me to assign the retrieved advice to a variable.