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

socila media via SCSS + JS

Alexei 831

@Batareika007

Desktop design screenshot for the Social media dashboard with theme switcher coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


JS script not great, but it works ) I will be glad for a hint how to write it better if possible. Thanks

Community feedback

@Ahmed96Mah

Posted

Hello Alexei,

These steps could generally improve your JavaScript code:

1- You could use arrow functions instead of regular ones. For Example you could say:

const toDark = () => {
   toggle.classList.remove('white-theme-toggle')
   ....
}

2 - You could use const instead of let for the first 5 lines, as it is always best practice to use it when possible

3- You could use a callback function instead of a function expression for the event listener. for example:

const toggleMode = () => {
  if (toggle_ball.classList.contains('toggle__ball_dark')) {
     ....
  }else {
     ....
  }
};

toggle.addEventListener("click", toggleMode);

4- You could use foreach loop or 'for of' loop instead of regular for loops .

card.foreach((item) => {
 item.classList.toggle('white-theme-card-bg');
item.classList.toggle('dark-theme-card-bg');
});

And generally, I think that you could merge both "toDark" & "toWhite" functions into one function and use 'toggle' instead of "add & remove" since the website will always have an initial style and all what you want is to flip or "toggle" the classes.

Have a nice day ;)

Marked as helpful

1

Alexei 831

@Batareika007

Posted

@Ahmed96Mah

Wow Thank for that! It's very useful information.

I will check all of it.

Have a great day !

0

@Ahmed96Mah

Posted

@Batareika007

Thank You ;)

By the way, nice job on making the page take the initial theme (dark-mode or light-mode) of the browser. I really liked that idea :)

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