Adds while loop to JavaScript

This adds a while loop to the JavaScript file.