correct syntax for for loop in javascript