add in javascript version of the code