I have following question.
I'm currently practicing with Rest-Api Calls. How can I make the code in the forEach loop run through completely before the rest is executed? My code is just for practice and doesn't make any sense otherwise. It would be nice if you would help me.
async function fetchSmth(){
let response = await fetch('https://api.coindesk.com/v1/bpi/currentprice.json');
let json = await response.json();
[json.bpi].forEach(async (element) => {
if(element.USD.code == "USD"){
let response2 = await fetch('https://catfact.ninja/fact');
let json2 = await response2.json();
document.body.innerHTML = document.body.innerHTML + `<div id='a_1'>${json2.fact}</div>`;
}
});
document.body.innerHTML = document.body.innerHTML + `<div id='a_1'>FAIL!!!</div>`;
}
fetchSmth();