fixed javascript for loop