Design comparison
Solution retrospective
I'm running into a problem with the toggle functionality. the border background colors change, unless I click on a country card FIRST then click on dark mode. help anyone?
Community feedback
- @lloydjohnlandezaPosted over 1 year ago
Nice pure javascript solution! It's nostalgic to see a javascript code without any framework/libraries.
Anyway to fix your issue on the border toggle you should check if the body has a class "dark-mode" before generating the html template for borderCountries.
The solution for it is below but I suggest you try doing it first before checking it.
- Spoiler Alert
- Spoiler Alert
- Spoiler Alert
- Spoiler Alert
const isInDarkMode = document.body.classList.contains('dark-mode') const borderDarkMode = isInDarkMode ? 'border-dark' : '' borderCountries = borders.length > 0 ? borders.map((border) => `<span class="border ${borderDarkMode}">${border}</span>`).join('') : 'None'
Marked as helpful1@MousteeMPosted over 1 year agothank you so much for this! I'll tinker with it some more and see how I can fix it. 😁@lloydjohnlandeza
1 - @Saad-HishamPosted over 1 year ago
great work I believe that the project is almost perfect I just have a small tip that may help you make it better since the API provide the pollution is just a number you need to format it with comma after every number field To format the population numbers returned by the API with commas, we can use regular expressions. Here's an example of how to use regex to add commas to the population number:
// Convert the population number to a string and replace any non-numeric characters with the letter 's'
const value = country.population.toString().replace(/[^0-9]/g, 's'); // Add commas to the population number at every thousandth place const formattedValue = value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
In the first line of code, we convert the population number to a string using toString() and then replace any non-numeric characters with the letter 's' using replace() and a regular expression.
In the second line of code, we use another regular expression with replace() to add commas to the population number at every thousandth place.
I hope this explanation is helpful. Keep up the great work!❤
Marked as helpful1@MousteeMPosted over 1 year agoOh yeah I was wondering how to go about that. thank you so much! :D @Saad-Hisham
1
Please log in to post a comment
Log in with GitHubJoin 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