if else statements and loops in JS