complete-javascript-course
complete-javascript-course copied to clipboard
I changed your code of countries API
I'm from Brazil so sorry any mistake with the english. When we run the code with Portugal you receive the neighbour Spain but if you run Brazil you just receive Argentina and Brazil have 10 neighbour so i developed something that show all neighbours with loop and without callback hell.
This shows all the neighbours
const getCountryData = function (country) {
fetch(https://restcountries.eu/rest/v2/name/${country})
.then(response => response.json())
.then(data => {
console.log(data)
renderCountry(data[0]);
let viz = []
for(let i = 0; i <= 18; i++){
const neighbour = viz.push(data[0].borders[i]);
}
//Country 2
for(let i = 0; i <= viz.length; i++){
fetch(https://restcountries.eu/rest/v2/alpha/${viz[i]}).then(response => response.json())
.then(data => {
console.log(data)
renderCountry(data, 'neighbour')
})
}
})
};
getCountryData('brasil');