[JavaScript] Asynchronous JavaScript: Promises, Async/Await, and AJAX - Chaining Promises
const getCountryData = function (country) {
// country 1
fetch(`https://restcountries.com/v2/name/${country}`)
.then(response => response.json())
.then(data => {
renderCountry(data[0]);
const neighbor = data[0].borders[0];
if (!neighbor) return;
//country 2
return fetch(`https://restcountries.com/v2/alpha/${neighbor}`);
})
.then(response => response.json())
.then(data => renderCountry(data, 'neighbor'));
};
// getCountryData('Spain');
getCountryData('usa');