Rearranged JS if statement