Skip to content

Instantly share code, notes, and snippets.

@jsrath
Last active November 15, 2018 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsrath/2a6f1c7638ce4de44f496e4eb3bf8ba8 to your computer and use it in GitHub Desktop.
Save jsrath/2a6f1c7638ce4de44f496e4eb3bf8ba8 to your computer and use it in GitHub Desktop.
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