Unobtrusive Easter Calculator
2. Converting the JavaScript
Join the Discussion
More of this Feature
Introduction The HTML The Stylesheet The JavaScript How it Works
Offsite
The only significant difference between the way this is coded and how JavaScript would interpret the statements is that all of the divisions need to discard any fractional part in order to give the right result. All of the numbers we need to work with in this calculation are whole numbers and the fractional parts are treated as remainders instead.
There are two ways that we can handle this. One would be to reorganize the code so that we calculate the remainder first and subtract that before doing the division. For example:
b = (year - c) / 100
Doing this will get rid of the fractions but it means that we have to significantly reorganize the code in order to get it to work and that means that we could end up making some mistakes in the calculation. The fewer changes that we make to the required calculations, the less chance we have of introducing an error. In order to avoid that we'll use Math.floor() to discard the fractional part of the result. We'll just wrap all of the divisions in that code and leave the order of the statements alone.
For the purpose of setting up our Easter Calculator we don't need to know how this formula actually calculates the Golden Cycle, Epact, Solar Equation, Lunar Equation, and Paschal Full Moon (which are what these calculations actually do), we only need to know that these calculations will produce the right answer. What we are most interested in here is how to write those calculations using JavaScript. If you are interested in how this calculation actually works to calculate Easter, use your favorite search engine and search for "Computus" or "Meeus/Jones/Butcher Gregorian algorithm". The pages you find should provide you with detailed descriptions of how and why these calculations are needed to determine when Easter falls in any year.
Everyone who isn't a mathematical genius should be able to see advantages to this. As long as you can locate an accurate formula for whatever calculation it is that you want to perform, and translate that into JavaScript, you can create a web page with a working JavaScript that performs that calculation for you.

