I have this function (it is a fetch function), and I need it to return a new API URL (using the same API variable). What am I not understanding here?
var generateUrl = function(city) {
var apiUrl = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=imperial&exclude=minutely,hourly,daily,alerts" + apiKey;
var response = fetch(apiUrl).then(function(response){
response.json().then(function(data) {
apiUrl = "https://api.openweathermap.org/data/2.5/onecall?lat=" + data.coord.lat + "&lon=" + data.coord.lon + "&exclude=minutely,hourly,alerts&units=imperial" + apiKey;
});
});
return apiUrl;
}