wrote code

updated java script with mathematics.