Skip to content
  • Learning paths
  • Challenges
  • Solutions
  • Articles
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 3 years ago

REST Countries API with color theme switcher using Vanilla JavaScript

fetch, sass/scss
Mo•840
@MohamedAridah
A solution to the REST Countries API with color theme switcher challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

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^^^

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Ivan•2,610
    @isprutfromua
    Posted about 3 years ago

    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 🤝⌨️

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub