Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

REST Countries API with color theme switcher using Vanilla JavaScript

#fetch#sass/scss
Mo 840

@MohamedAridah

Desktop design screenshot for the REST Countries API with color theme switcher coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
  • API
4advanced
View challenge

Design comparison


SolutionDesign

Solution retrospective


Hello Everyone, hoping you 're doing fine...

i want to know you feedbacks for this project... specially about javascript.

Have a good day everyone^^^

Community feedback

Ivan 2,630

@isprutfromua

Posted

Hi there. You did a good job 😎

keep improving your programming skills🛠️

your solution looks great, however, if you want to improve it, you can follow these steps:

  • It would also be great to show a spinner when the page loads, or to display country loading messages

  • instead of duplicating variables, you could create a base address and add paths. And it is better to make them constants, because you do not change them.

let baseApiLink = "https://restcountries.com/v2/all";
let regionQuery = `https://restcountries.com/v2/region/`;
let nameQuery = `https://restcountries.com/v2/name/`;
let alphaQuery = `https://restcountries.com/v2/alpha/`;
  • Code duplicating
   if (light) {
      darkMode(switchBtnText, switchBtnIcon);
      light = false;
    } else {
      lightMode(switchBtnText, switchBtnIcon);
      light = true;
    }
  • One of the possible optimization methods:
      darkMode(switchBtnText, switchBtnIcon);
      light = !light;

  • It is also better to optimize the function to enable themes:
function chanegMode(text, icon, mode) {
  let iconClasses = `fa-regular theme-icon ${mode === 'dark' ? 'fa-sun-bright' : 'fa-moon'}`;
  text.textContent = mode === 'dark' ? 'light mode' : 'dark mode';
  icon.className = iconClasses;
 mode === 'dark' 
 ? document.body.classList.add("dark-theme")
: document.body.classList.remove("dark-theme")
}

I hope my feedback will be helpful. You can mark it as useful if so 👍

Good luck and fun coding 🤝⌨️

1

Please log in to post a comment

Log in with GitHub
Discord logo

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