結果 : javascript wait for if statement to finish