converted calculations

used the code written in java from the previous project and changed it
to javascript
~2