To keep from doing unnecessary work (and to make it possible to restart later), we need to create another boolean variable that keeps track of whether the animation should stop.

- Create a new variable called
stopAnimation
and set it tofalse
. - Use
&&
in the if statement to make it check thatstartAnimation
is true AND thatstopAnimation
is NOT true. The!
character means “not”.