probably a stupid/very simple question but I can’t figure it out. I get the sat_id from an API, which I want to append to a new API URL. So I need the sat_id outside the function. How do I do that?
Here is the script:
const sat_url = 'https://api.wheretheiss.at/v1/satellites';
let sat_id = 0;
async function getISS() {
const response = await fetch(sat_url);
const data = await response.json();
sat_id = data[0].id;
console.log(sat_id); //here is the correct sat_id
}
getISS();
console.log(sat_id); //here ist the "0" from above but not the sat_id from the function
const data_url ='https://api.wheretheiss.at/v1/satellites/' + sat_id;
translate by google 🙂