Cleaned up JS

Consolidated newTask variable.
If had no associated else statement, so a While loop should suffice.