Skip to content

Instantly share code, notes, and snippets.

@claraj
Created February 20, 2020 23:22
Show Gist options
  • Save claraj/78ebbe3c816af7a4c36bd39f6916f9d9 to your computer and use it in GitHub Desktop.
Save claraj/78ebbe3c816af7a4c36bd39f6916f9d9 to your computer and use it in GitHub Desktop.
function fetchingData( done ) {
fetch(`https://api.worldbank.org/v2/country/${countryCode}?format=json`)
.then(res => res.json())
.then(countryData => {
console.log(countryData);
console.log(countryData[1][0]['capitalCity']);
let capCity = countryData[1][0]['capitalCity'];
done(capCity)
})
.catch(err => {
console.log(err)
});
}
// when the page loads, select an element at random from the countriesAndCodes array
// display the country's name in the randomCountryElement
submitButton.addEventListener("click", () => {
// let userAnswer = userAnswerElement.value();
fetchingData( function(capCity) {
console.log(capCity)
})
});
function fetchingData( ) {
return fetch(`https://api.worldbank.org/v2/country/${countryCode}?format=json`)
.then(res => res.json())
.then(countryData => {
console.log(countryData);
console.log(countryData[1][0]['capitalCity']);
let capCity = countryData[1][0]['capitalCity'];
return capCity
})
}
// when the page loads, select an element at random from the countriesAndCodes array
// display the country's name in the randomCountryElement
submitButton.addEventListener("click", () => {
// let userAnswer = userAnswerElement.value();
fetchingData().then( capCity => {
console.log(capCity)}
)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment