Java Script Calculators by Bob McClure

  I have been learning the rudiments of JavaScript programming, which has also required learning something about HTML.
  You might be interested in the attached calculators.

The ScientificCalculator was written by Denis Makarov of and download from  

(I found that the calculator written by Denis Makarov did not work properly on hyperbolic functions. I found out the reason and fixed the problem. I sent my corrected script back to Denis and he is going to update his web pages.)

 The SP Calculator was inspired by a simple four-function calculator downloaded from

  These calculators work on different principles. The scientific calculator calls functions written in Javascript to accomplish its operations.

The SP Calculator calls the intrinsic JavaScript "eval" function. The "eval" function reads, interprets, and executes multiple lines of Javascript code. In a sense, the calculator is programmable. You can just paste in code, which you could have have previously written to a text file. You can build your own library of functions to copy and paste in.  

Two S-P seismic travel-time function are built in. Click on a button (dist or SP), type in a numerical argument, and a closing parenthesis. Click "Go" to compute the distance of an earthquake from the time difference between the P- and S-arrival times, or visa versa.

These functions are the results of my efforts on the power series representation of S minus P versus Distance tables. Not strictly accurate, but a good approximation.
  My approach was to lift the data from the JB tables for S and P at 33km depth. I subtracted the P times from the S times and ended up with a table of (S-P) vs distance. I then did an 8th order least-mean-square fit of (S-P) vs distance to get one set of coefficients useful for estimating time difference when you know the distance, and then fitted to distance vs (S-P) to get coefficients useful for estimating distance when you know the time difference.

See also the stand-alone travel time calculator.

9/7/2006 and 9/17/2006