JSFiddle - React, Tailwind, and code Playground
JavaScript
const cityAPI = 'https://www.mocky.io/v2/5a945fa435000074009b0e78';
const weatherAPI = 'https://www.mocky.io/v2/5a947dfa35000072009b0eb9?city=';
function asyncGetCity() {
return fetch(cityAPI).then(response => response.json());
}
function asyncGetWeather(city) {
return fetch(weatherAPI+city).then(response => response.json());
}
let cityName;
return asyncGetCity()
.then(function (city) {
cityName = city.name;
return asyncGetWeather(cityName);
})
.then(function(weather) {
console.log(cityName)
console.log(weather.temp + weather.unit);
});