Skip to content

Instantly share code, notes, and snippets.

@jsrath
Last active Nov 15, 2018
Embed
What would you like to do?
function getCountryName(event) {
event.preventDefault();
const countryOutput = document.querySelector('#country-output');
let code = document.querySelector('#country-text').value;
countryOutput.innerHTML = '';
fetch(`https://restcountries.eu/rest/v2/ callingcode/${code}`)
.then(result => result.json())
.then(result => {
result.map(country =>
(countryOutput.innerHTML +=
`<li>${country.name}</li>`));
})
.catch(() => {
countryOutput.innerHTML =
`<h3>Country Not Found</h3>`;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment