Created
February 20, 2020 23:22
-
-
Save claraj/78ebbe3c816af7a4c36bd39f6916f9d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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