47 Answers to Review Questions. “Digital Media Primer” Yue-Ling Wong
Chapter 14
When applicable, please select all correct answers.
1. In the analogy of building a house, ______ is like a blueprint and ______ is like the actual house built
from the blueprint.
2. ______ is an instance of ______.
A. class; an object
B. An object; a class
3. In OOP, what are the two aspects you use to describe an object? (Select two)
A. Class
B. Instance
C. Properties
D. Behaviors
4. In OOP, the properties of an objects are defined as ______.
A. classes
5. In OOP, the behaviors of an object are defined as ______.
A. classes
B. instances
C. object literals
D. constructor functions
E. methods
F. variables
6. Fill in the blanks with the following terms: constructor functions, object literals, prototypes, variables,
methods
JavaScript does not have classes. However, you can use something called ______ and ______ to
implement the class concept. This chapter introduces ______ only.
7. What is the general syntax to invoke a method on an object?
A. ClassName.method()
48 Answers to Review Questions. “Digital Media Primer” Yue-Ling Wong
B. objectName.method()
8. var rectangleA = {
x: 200,
y: 10,
width: 40,
height: 20,
moveDown: function () {
this.y += 5;
}
};
In the code above, rectangleA is ______.
A. an object
B. a constructor function
9. var rectangleA = {
x: 200,
y: 10,
width: 40,
height: 20,
moveDown: function () {
this.y += 5;
}
};
Given the code above,
(i) write a statement to change the x value of rectangleA to 150.
(ii) write a statement to invoke the method moveDown() on rectangleA.
10. function Rectangle(x, y)
{
this.x = x;
this.y = y;
this.width = 40;
this.height = 20;
this.moveDown = function ()
{
this.y += 5;
};
}
In the code above, rectangleA is ______.
A. an object
B. a constructor function
11. function Rectangle(x, y)
{
this.x = x;
this.y = y;
49 Answers to Review Questions. “Digital Media Primer” Yue-Ling Wong
this.y += 5;
};
}
Given the code above, write a statement to create a Rectangle object named rectangleA with x=200
and y=10.
12. function Rectangle(x, y)
{
this.x = x;
this.y = y;
13. (i) Six stars are created from a Star constructor function using six new statements as follows:
var star1 = new Star();
var star2 = new Star();
var star3 = new Star();
var star4 = new Star();
var star5 = new Star();
var star6 = new Star();
Create an array, say stars, and rewrite the code using a for-loop to store the Star objects in the
array.
(ii) Suppose the Star object have two methods: spin() and fall(). Write a for-loop to invoke both
methods on all six stars.