fix syntax in JS version
fix JS errors and add testing
Merge pull request #4 from dcollien/master

bring up to date