Created a while loop in JavaScript