JS - Conditionals and loops