Obvsiouly I'm very new to Javascript. For an app that I'm building, I need to save the data I get from a fetch request into a variable that ideally I can access outside of my function. Any light on this would be hugely appreciated.
Here's my code:
function generateNewQuote() {
fetch('https://api.whatdoestrumpthink.com/api/v1/quotes/random')
.then(response => response.json())
.then(data => {
const newMes = data.message;
console.log(newMes );
});
}
I need to get the value of my newMes variable into a variable that I can specify in the global scope or alternative a way to access the newMes variable locate inside my generateNewQuote function in the Global Scope.