Nested While Loop Javascript Syntax