Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Animation and Games JavaScript

Total questions: 11

Worksheet time: 6mins

Name
Class
Date
1.
Which of the following statements are true about ball? 
I – ball is a local variable 
II – the ball variable in draw is different from the ball variable in start 
III – ball is a global variable 
IV – ball’s scope includes both start and draw
a)
III and IV
b)
I and II
c)
III only
d)
I, II, III, and IV
2.
a)
Animates a ball by moving it down and to the right once every 20 milliseconds.
b)
Animates a ball by moving it up and to the right once every 20 milliseconds
c)
Animates a ball by moving it down and to the right every 20 seconds
d)
Animates a ball by moving it up and to the right once every 20 seconds
3.
The given 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. Which statement would stop the animation in this program?
a)
stopTimer(ball.move(2, 2));
b)
stopTimer(draw);
c)
stopTimer(draw());
d)
stopTimer(draw, 20);
4.
We extend our draw function to include the code above. How many times will the ball be moved before the animation stops?
a)
2
b)
20
c)
25
d)
40
5.
Which of the following are techniques that make our code more reusable? 
I – Using constants instead of magic numbers 
II – Using specific values in our functions rather than using parameters 
III – Writing multiple functions that solve small subproblems rather than one function that solves the entire problem. 
IV – Writing as few lines of code as possible
a)
I, II, and III
b)
I, II, III and IV
c)
I and III
d)
II and IV
6.
Which function has better reusability?
A: 
function drawCircle(x, y, radius, color) { var circle = new Circle(radius); circle.setPosition(x, y); circle.setColor(color); add(circle); } OR B. 
function drawGreenCircleInCenter(radius) { var circle = new Circle(radius); circle.setPosition(getWidth() / 2, getHeight() / 2); circle.setColor(Color.green); add(circle); }
a)
A
b)
B
7.
How many circles of radius 10 will fit vertically stacked in a window that has height 100? The circles should not overlap, the bottom of one circle should touch the top of the next circle.
a)
100
b)
20
c)
10
d)
5
8.
This is a circle on our canvas named ball. What are the coordinates of point A?
a)
ball.getX(), ball.getY()
b)
ball.getRadius(), ball.getY()
c)
ball.getX() + ball.getRadius(), ball.getY()
d)
ball.getX(), ball.getY() + ball.getRadius()
9.
What statement should we use to determine if ball is hitting the bottom edge of the window?
a)
if(ball.getX() + ball.getRadius() < 0){ //ball is hitting bottom edge }
b)
if(ball.getY() - ball.getRadius() < 0){ //ball is hitting bottom edge }
c)
if(ball.getY() + ball.getRadius() > getHeight()){ //ball is hitting bottom edge }
d)
if(ball.getY() + ball.getRadius() < 0){ //ball is hitting bottom edge }
10.
How can we determine if ball’s left edge is hitting a different shape on our canvas named box?
a)
if(ball == box){ //ball's left edge is hitting box }
b)
var elem = getElementAt(ball.getX() - ball.getRadius() - 1, ball.getY()); if(elem == box){ //ball's left edge is hitting box }
c)
var elem = getElementAt(ball.getX() - ball.getRadius() - 1, ball.getY()); if(elem != null){ //ball's left edge is hitting box }
d)
if(ball.getX() - ball.getRadius() - 1 == box){ //ball's left edge is hitting box }
11.
The following code moves a ball across the screen at a rate of dx in the x direction and dy in the y direction. What do we need to add to line 19 to have the ball bounce off the top of the window. 
a)
dy = -dx;
b)
dy = -dy;
c)
dx = -dx;
d)
ball.setPosition(ball.getX(), getHeight() - ball.getRadius());