Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 2 years ago

Calculator app with theme swtcher

accessibility, theme-ui
Yefree Valdez•940
@yefreescoding
A solution to the Calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


This is my solution for this amazing challenge

Built with:

  • HTML5. (I tried to use as many semantic tags as I could)
  • CSS. (Pure CSS)
  • JavaScript.

Challenges while tackling this project:

  • The theme switcher. My solution was to create three input type radio and assign each one of them a data-theme:
<div>
<input
  data-theme="theme_A"
  class="theme_toggle"
  name="theme"
  type="radio"
  checked
/>
<input
  data-theme="theme_B"
  class="theme_toggle"
  name="theme"
  type="radio"
/>
<input
  data-theme="theme_C"
  class="theme_toggle"
  name="theme"
  type="radio"
/>
</div>
  • Then create a function in my js file to get the value from the data theme, and set it as a class to my html :root
const themeToggle = document.querySelectorAll('.theme_toggle');

themeToggle.forEach((toggle) => {
  toggle.addEventListener('click', (e) => {
    const root = document.documentElement;
    const theme = e.target.getAttribute('data-theme');
    root.className = theme;
    localStorage.setItem('theme', theme);
  });
});
Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Yefree Valdez's solution.

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

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

Frontend Mentor

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

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