Please use code-tags when posting code. Don’t post plain-text as it’s very difficult to read. You can also edit your post to include this too.
Really, this is just a case of you not following your own code logically. Step through it in a debugger or just follow it with your mind: You check if flipX is true and if so then set it to false and then immediately after you check if it’s false and set it to true. In other words, you flip it twice from true → false → true again.