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

18th Task: Calculator App๐Ÿงฎ๐Ÿค“ Give it a try๐Ÿ‘ˆ๐Ÿปโœ…โœ…๐Ÿ˜

Rodrigoโ€ข480
@RodrigoHLC
A solution to the Calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I'd been looking forward to working on this project for days, and I'm very happy with how quickly I completed the markup and CSS. The screen responsiveness works GREAT๐Ÿ™Œ๐Ÿป๐Ÿ™Œ๐Ÿป Even the Javascript didn't take a huge amount of time. I think I completed about 90% of the thing in a workday. The other 10% was me leaving no stone unturned, planning for every possible scenario when writing input (e.g.: making sure it's not possible to write two operands together like "++", "/*", making sure you can't write something like "00000" or "0.03.2.0") and some things that were a little more difficult to fully figure out; as anyone who's programmed a calculator will tell you (this is my second time), the function for the Period tends to be the most annoying, head-scratching one๐Ÿฅด

Extra mile

  • Played a little with the box shadows on the buttons to make them look a little more - 3D and make them look like they're being pressed down.
  • Added a custom scrollbar to the calculator's screen in case the input gets too long.
  • Used eventListeners to make sure you can also use it with your keyboard, though this is a fairly standard "idea".
  • I did not use prefers-color-scheme but I did use localStorage to make sure the user's preferred color scheme is saved.

Issues I wasted a lot of time in the end trying to get the buttons to work on mobile, but I couldn't for-the-life-of-me get it to work, at least not on my Moto G7 Play (since I had to delete and re-deploy on Github everytime I made changes, I only tried to make the Number buttons responsive on mobile, but I couldn't do it). Any advice here will be highly appreciated. I tried using touchstart, touchend, onclick, and even changing the element for the calculator's screen from a <textarea> to an <input> element, but to no avail๐Ÿ˜ค๐Ÿ˜ค

Here's a relevant snippet of my code. numbers is a node list of <button> elements. Clicking works, tapping doesn't:

// EACH BUTTON HAS A value ATTRIBUTE SET TO ITS NUMBER
numbers.forEach(num => num.addEventListener("click",()=>{
    numberFunc(num.value)
}))

numbers.forEach(num => num.addEventListener("touchstart",(e)=>{
    e.preventDefault();
    numberFunc(num.value)
}))
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 Rodrigo'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