Added while loop to .js file