Hi there,
I’m currently completing my FreeCodeCamp Local Weather project, however I have run into a problem.
In the function below, a variable is being returned in it’s undefined state, before the getJSON() function can alter it. I can’t figure out how to make it return the correct value;
function getWoeid(lat, long) {
var woeid;
var url = 'https://www.metaweather.com/api/location/search/?lattlong='+lat+','+long;
console.log(url);
$.getJSON( "https://cors.io/?https://www.metaweather.com/api/location/search/?lattlong="+lat+","+long, function( data ) {
console.log(JSON.stringify(data));
woeid=data[0].woeid;
console.log(woeid);
});
return woeid;
}