Code for While Loop in JS