When I first started adding calculator scripts to this site one reader suggested that I write a tutorial on how to create a calculator script so that they and other readers could create their own calculators. This seemed a good idea since obviously I can't write scripts for every calculator that people are likely to want. There are such a wide range of possible calculators that I am certain that everyone who wanted to could create one completely different from everyone else's.
There are also several different ways (at least) to create a calculator script. I have used a couple of different approaches with the first two calculator scripts that I wrote as the requirements were completely different. For the purposes of this tutorial then I will consider just one approach to creating a calculator script. Also so that you can see how the process works in practice let's actually create a new calculator as we go.
For the purpose of demonstrating the process that I have used to build some of the calculator scripts on this site, let's build an Easter Calculator where we can enter the year and have the calculator tell us the date that Easter Day falls on in that year. Of course the calculator that you will want to build will probably be calculating something completely different but this should allow me to demonstrate the process of creating a calculator involving quite complex calculations.
The first step is to write down the formula that the calculator we are about to create needs to use to peform it's calculations. Depending on what your calculator is going to calculate you may already know the formula. If you don't know the formula you will need to find it either in one of your reference books or by researching to find the formula either at a library or via the internet. In the case of the Easter calculator I located an appropriate formula in one of the books in my history collection (although the formula in the book actually contains a misprint - but more of that later).
Having found the required formula for our calculator the next step is to rewrite the formula into Javascript.
