Projects

Calculator

A calculator using recursive algorithm

I decided to build a calculator as an exercise to learn JavaScript. On top of being a good problem to combine JS and DOM-manipulation, it was a fun exercise in algorithms too.

The application runs a recursive algorithm on the given calculation, solving from the 'deepest sub-calculation' to the 'surface'.

Basically, if the calculation is the following: 5+(4/2), the algorithm solves it in the following steps:

  1. 5+(4/2)
  2.   (4/2)
  3.    4/2
  4.      2
  5. 5+2
  6. 7

The app isn't perfect as it has at least one know bug (try entering '+(-)' -- it shouldn't let you enter incorrect inputs) and the ANS feature was added as an afterthought and works like one. Otherwise I'm pretty happy with it, considering the context.

Tagged with:javascript
Calculator