Which of the following are good examples of things that should be stored as global variables?
I - A ball for a game that is used in multiple functions
II - A counter that keeps track of how many times the user has clicked the mouse
III - A for loop counter variable
IV - The color of a rectangle that is only used in one function
I and II only
Key Terms
Which of the following are good examples of things that should be stored as global variables?
I - A ball for a game that is used in multiple functions
II - A counter that keeps track of how many times the user has clicked the mouse
III - A for loop counter variable
IV - The color of a rectangle that is only used in one function
I and II only
In the following code
function start(){
mouseClickMethod(clickHandler);
}
function clickHandler(e){
//your code here
}
How can we get the graphical element at the location of the user click?
var elem = getElementAt(e.getX(), e.getY());
9.9.7: Click for Collision
var blueCircle;
var redCircle;
var RADIUS = 25;
var DX_RED = 6;
var DX_BLUE = 4;
var DELAY = 40;
var click = 0;
var paused = f...
9.9.8: Drag and Drop
var NUM_CIRCLES = 3;
var RADIUS = 30;
function start(){
drawCircles();
// Add your drag and drop code
mouseDownMethod(drag);
mous...
What does this program do?
var ball;
function start(){
ball = new Circle(40);
add(ball);
setTimer(draw, 20);
}
function draw(){
ball.move(2, 2);
}
Animates a ball by moving it down and to the right once every 20 milliseconds.
In the following code:
var ball;
function start(){
ball = new Circle(40);
add(ball);
setTimer(draw, 20);
}
function draw(){
ball.move(2, 2);
}
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
III and IV
Related Flashcard Decks
Study Tips
- Press F to enter focus mode for distraction-free studying
 - Review cards regularly to improve retention
 - Try to recall the answer before flipping the card
 - Share this deck with friends to study together
 
| Term | Definition | 
|---|---|
Which of the following are good examples of things that should be stored as global variables?  | I and II only  | 
In the following code  | var elem = getElementAt(e.getX(), e.getY());  | 
9.9.7: Click for Collision  | var blueCircle;  | 
9.9.8: Drag and Drop  | var NUM_CIRCLES = 3;  | 
What does this program do?  | Animates a ball by moving it down and to the right once every 20 milliseconds.  | 
In the following code:  | III and IV  | 
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:  | stopTimer(draw);  | 
We extend our draw function to include:  | 25  | 
Which of the following are techniques that make our code more reusable?  | I and III, and IV  | 
Which function has better reusability?  | function drawCircle(x, y, radius, color){  |