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

Calculator app solution

react, tailwind-css, typescript, vite
Omar•560
@to-my-learning-path
A solution to the Calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Which areas of your code are you unsure of?

  • How to store the theme on local storage and update the current theme toggler value.
  • Implement the correct Calculator functionality.
Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Kamlesh Rajesh Yadav•5,040
    @Kamlesh0007
    Posted about 2 years ago

    When the user clicks the toggle button to switch themes, you should update a global variable or state variable to keep track of the current theme (e.g., isDarkMode).

    After updating the theme variable, you should save its value to local storage using the localStorage.setItem() method. For example:

    javascript code localStorage.setItem('theme', isDarkMode ? 'dark' : 'light'); This code saves the theme value as a string ('dark' or 'light') with the key 'theme' in the local storage.

    When the user loads the page or refreshes it, you should retrieve the theme value from local storage using the localStorage.getItem() method. For example: javascript code const savedTheme = localStorage.getItem('theme'); This code retrieves the theme value as a string with the key 'theme' from the local storage.

    After retrieving the theme value, you should update the theme variable and the toggle button value accordingly. For example: javascript code const isDarkMode = savedTheme === 'dark'; toggleButton.value = isDarkMode; This code updates the isDarkMode variable based on the saved theme value and updates the toggle button value to reflect the current theme.

  • Chamu•13,820
    @ChamuMutezva
    Posted about 2 years ago

    Hi Omar

    So far so good with your project, well done. Kamlesh has explained well on how to handle the local storage issue.

    Using the eval is genarally not recommended as among other things considered a security risk to users. See the following eval - MDN.

    Here are some issues to look at when dealing with a calculator

    • how to deal with floating number calculations , for example do the following 0.1 + 0.2 and check the result.
    • set a maximum length for the operands , you cannot have a calculator that will take any number as long as the keyboard is pressed.
    • set a condition such that , when the decimal point is already present in the number, then no other decimal point should be accepted. For example 0.89.3 should not be permitted

    Happy coding.

  • Kamlesh Rajesh Yadav•5,040
    @Kamlesh0007
    Posted about 2 years ago

    To properly center the component in the page, you should use Flexbox or Grid layout. You can read more about centering in CSS here 📚. For this demonstration we use css Grid to center the component. body { min-height: 100vh; display: grid; place-items: center; }

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 all CSS, SCSS and Less files in your repository.

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.

How does the JavaScript validation report work?

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

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

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

Log in with GitHub

Frontend Mentor for Teams

Frontend Mentor for Teams helps companies and schools onboard and train developers through project-based learning. Our industry-standard projects give developers hands-on experience tackling real coding problems, helping them master their craft.

If you work in a company or are a student in a coding school, feel free to share Frontend Mentor for Teams with your manager or instructor, as they may use it to help with your coding education.

Learn more

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