JavaScript - Nested if in JavaScript