Making a moving object change direction when it reaches a certain position?

As stated above, please use code-tags when posting code. As I’m sure you can see, unformatted code is difficult to follow.