Last active
November 15, 2018 13:29
-
-
Save jsrath/2a6f1c7638ce4de44f496e4eb3bf8ba8 to your computer and use it in GitHub Desktop.
This file contains 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 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