I think I just finished my calculator project. My goal with the project was to do two things: 1) learn about closures, and 2) try to emulate the behavior of a physical calculator as much as possible.
I did calculation chaining a little different from the sample project. Like a real calculator, mine gives a running total as you punch in new operations. It also allows you to repeat the last calculation by hitting the calculate button again.
I tried to keep all the calculator logic in one file (calculator.js) and all the page rendering in a second file (script.js). That plus using closures helped a lot but the code still managed to get pretty messy by the end.
I would appreciate any feedback, especially if you find any bugs-- of which i am sure there are many. Theres definitely problems with how it handles large numbers and I chose to just limit the number of digits to 9. Instead I should switch to scientific notation.
Thanks for checking it out! To be honest I totally forget to try to make it scale to mobile. I’m really not that interested in making UIs and just copied the interface from OSX’s desktop calculator pixel for pixel.
I guess i’ll have to go back through the front end tutorials and try to figure out how to make the UI responsive.
works pretty well … couple of things though … its not allowing numbers like .011 etc or 2.011 and its kind of overflowing for things like 7/3 …
One thing i dont like is not showing the operator that was pressed eg press + nothing shows …