Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 4 years ago

Calculator app - Both Keyboard & Mouse click events included.

Sunny78inator•60
@prathyushSunny
A solution to the Calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I have only implemented 2 themes though, sorry for that. I wasn't aware of traditional grid system so I had to use bootstrap grid system in order to layout the calc buttons. Anyways, please do check how I made the transition from Light <-> Dark (from calc.js line: 215) and suggest me if there's a rather easier or concise way to implement the same.

PS: I'm still in the learning stage, will be learning ReactJS soon.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Account deletedPosted almost 4 years ago

    I'm pretty sure there's a lot of ways of implementing the theme switching, and your way works very well.

    The calculator is perfectly functional, and adding keyboard inputs is a plus. I just have a few suggestions;

    How about you give the same functionality to the enter key as the equals button, 'cause the backspace works, but the enter key doesn't, it just returns the last number you clicked on.

  • Praneet Dixit•120
    @PraneetDixit
    Posted almost 4 years ago

    Hi!

    Your theme switching implementation looks quite good.

    Another way of theme switching is using custom properties and toggling a single class to change the properties.

    Here is an example -

    /*CSS*/
    
    body{
      --text-color: #000;
      --background-color: #fff;
    }
    
    body.dark{
      --text-color: #fff;
      --background-color: #000;
    }
    
    .someElement{
      color: var(--text-color);
      background-color : var(---background-color);
    }
    
    //JS
    themeSwitchContainer.onclick = function() {
        document.body.classList.toggle('dark');
    }
    

    You can play around with this to include more themes.

    Your calculator is pretty functional.

    +1 for keyboard inputs.

  • P
    Patrick•14,265
    @palgramming
    Posted almost 4 years ago

    I like your icons in your theme slider

    I can enter 6+6 on the keyboard but when I hit the enter key on the keyboard it just shows 6 the enter key on the numpad then shows 0

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

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit 1st-party linked stylesheets, and styles within <style> tags.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

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