Change direction javascript