How do I do this program?

Ok.
Think about what is happening to x every time through loop.
As the code stands, there is no point reading buttonState in setup...and you've changed the posted code again.