REST Countries API using HTML, SASS and Vanilla JS

Solution retrospective
⚠️⚠️NEED YOUR HELP⚠️⚠️
Hi Frontend Mentor Community! This is my solution for this challenge:)
I would like to get your help...
- How can I get borders info from API? I manage to get their name, but struggling with directing to their details pages.
- How can I apply SASS to elements which are generated by JavaScript? I would like to apply background-color and also some style to tag, however, changes won't be applied to the elements which are inserted by JS
Your help would be much appreciated!
Please log in to post a comment
Log in with GitHubCommunity feedback
- @lipe11
Hi, very brave to use vanilla JS on this project :)
For the borders, there's and endpoint to get country data by its code. You could get the country name there
https://restcountries.com/v3.1/alpha/{code}
I think the async/await syntax makes the code simpler in this case.Something like this:
async function fetchCountry(name) { const country = { name: { common: 'Guatemala' }, borders: ['BLZ', 'SLV', 'HND', 'MEX'] } return { name: country.name.common, borders: await Promise.all( country.borders.map(fetchCountryName) ) } } async function fetchCountryName(code) { const res = await fetch(`https://restcountries.com/v3.1/alpha/${code}`) const [country] = await res.json() return country.name.common } fetchCountry().then(console.log)
For the SASS issue, I'm not sure if I understood the problem correctly, but maybe
tag.classList.add('className')
might do the trick.
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord