Why was the US in such a hurry to build a rocket to get to the moon?

JFK set a challenge for NASA to land a man on the moon in a speech. We were also in the middle of a space race during the Cold War with Russia.