26.9k views
0 votes
The following program animates a ball by setting a timer to move the ball across the screen. We want the animation to stop whenever the user clicks the mouse:

var ball;

function start(){
ball = new Circle(40);
add(ball);
setTimer(draw, 20);
mouseClickMethod(stopAnimation);
}

function draw(){
(2, 2);
}

function stopAnimation(e){
//your code here
...
}
Which statement would stop the animation in this program?

User Anubhaw
by
8.1k points

1 Answer

2 votes

Final answer:

The statement that would stop the animation in this program is stop Animation. To stop the animation, add code inside the stop Animation function that cancels the timer.

Step-by-step explanation:

The statement that would stop the animation in this program is stop Animation. This function is called when the user clicks the mouse, and it is responsible for stopping the animation. To stop the animation, you can add code inside the stop Animation function that cancels the timer previously set by the set Timer function. This can be done using the clear Timer method and passing the ID of the timer as an argument. Here's an example:

function stop Animation(e) {clear Timer(draw);}
User Omry Zobel
by
8.3k points