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

Calculator App - HTML + CSS + JS, tried to focus on accessibility

Agata Liberska•4,075
@AgataLiberska
A solution to the Calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Please try it out and if there's any errors please let me know so I can fix them. Copied most of the behaviour (when it comes to input, display and navigation) from Windows system calculator. I tried to make it accessible so keyboard navigation can be used (numbers + operators or use arrows to navigate keypad). Color themes can be switched with keyboard too. However! I found out that NVDA screen reader hijacks arrow keys however so things don't work as they planned, and overriding that seems counter productive. I also checked with Thunder and while the navigation works fine, it doesn't read out much - but I've only just installed it so haven't had much time to get used to how it operates. Lots more to learn I guess :)

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • tediko•6,700
    @tediko
    Posted almost 4 years ago

    Hello, Agata! 👋

    Congrats on finishing another challenge! 🎉 Your solution looks very good and also responds well. I really like the idea with tutorial displaying in modal. Hover effect on keys when user input from directly from keyboard is also a nice touch! Here's my few tips:

    • After division by zero error pop up your calculator doesn't reset and I can to this error add next value - for example: 100 / 0 = not allowed, and then I click + 10 and it display NaN+10. It should either reset or take 0 as a "previous value".
    • One additional function that you can add is to perform last operation again. For example 2+2=4 and another click on equal button will be 6 since result our previous equation was 4 and our last input was 2 so 4+2=6.

    Good luck with that, have fun coding! 💪

  • Raymart Pamplona•16,040
    @pikapikamart
    Posted almost 4 years ago

    Hey, really great work on this one. Layout is really good and those custom key navigation is really awesome.

    Just a heads up, when a user press arrow keys, since pressing up and down scrolls the layout right and maybe a user wants to scroll down, they'll just press arrow keys. But since for every press, you are calling the moveFocus function, so if a user is not in focus inside the calculator buttons, it passes an undefined value from the findFocusedIndex since there are no node elements that have the focus, thus prompting many error for every arrow click a user made which you can see in the console.

    So a quick fix, on your handlekeys.js module, inside the handlekeys function, wrapped the switch statement inside an if statement, checking if the currentIndex variable have a valid data.

      if (currentIndex != undefined) { 
        the switch statement goes inside 
       }
    

    You still need to check if it is undefined because if (currentIndex) is the only passed condition, it won't read index 0 since 0 is false.

    Aside from that, really really great job on this ^^^

  • ApplePieGiraffe•30,525
    @ApplePieGiraffe
    Posted almost 4 years ago

    Hello, Agata Liberska! 👋

    Wonderful job on this challenge! 👏 I'm afraid I don't have much to suggest, either, but I think you've done some really nice work! 😀 I was actually looking around for the instruction modal that I read about in the others' feedback and then found it, of course, when using the keyboard to navigate the page! 😅 It's so nice that you've really thought about keyboard functionality for this challenge and the calculator's working pretty well! 👍

    Looking forward to your next solution! 😉

    And as always, keep coding (and happy coding, too)! 😁

  • Anna Leigh•5,135
    @brasspetals
    Posted almost 4 years ago

    Hi, Agata! Awesome job on this one! 🙌

    You've already gotten some really helpful feedback, and I don't think I have much to add but more praise. The instruction modal was a neat idea, and I had fun playing around with the keyboard controls. Everything seemed to work great for me! 👍

    Looking forward to your next solution - happy coding!

  • ellienndea•130
    @ellienndea
    Posted almost 4 years ago

    Hi Agata, this calculator app is really great. On my laptop it works perfectly fine with mouse and keyboard. :) I really like your focus on accessibility, it's so important! Happy coding 😊 Linda

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

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

Oops! 😬

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

Log in with GitHub