let city;
let c;
async function getCity() {
let apiKey = '9ddf7197ff9633535259c99aa0716c329981d1514f05e2e1e2015803';
let response = await fetch(`https://api.ipdata.co?api-key=${apiKey}`);
let data = await response.json();
city = data.city;
return city;
}
getCity().then(
function (value) {
c = value.city;
},
function (error) {
console.log(error)
}
);
console.log(c);
How do I assign a value to a global variable so that it can be use anywhere in the code. As I tried this method but I am getting "undefined" as my solution from console.log.