Update javascript

-added more comments to explain code