WorksheetsChapter 5 : JavaScript Objects & Arrays
Total questions: 20
Worksheet time: 13mins
How many values or properties can an Object contain
One value/properties
Two values/properties
Multiple values/properties
Identify the name of the object in the following code:
var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }
car
"EXPLORER"
model
var
Identify a key in the following code:
var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }
car
"EXPLORER"
model
var
Identify a value in the following code:
var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }
car
"EXPLORER"
model
var
How would you access the value "Ford"
var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }
car.Ford;
car["brand"];
car.getbrand;
car.brand;
What is DRIVE in the code below?
var car = {
DRIVE: function()
alert("Drive");
}
A property
A method
A variable
A function
What is the code that allows you to make use DRIVE?
var car = {
DRIVE: function()
alert("Drive");
}
drive()
DRIVE()
car.drive()
car.DRIVE()
What does the following code do?
var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }
var text = "";
for (var x in car) {
text += car[x] + " ";
}
Displays all the code in the object
Displays all the values in the object
Displays all the names of the keys in the object
Which of these creates an array in Javascript named myNumber that contains the following numbers:
5, 7, 11, 23, 1
Use the var keyword to create variables
(a)
Which will retrieve the "Singapore" from the following array?
var countries = ["Thailand", "Myanmar", "Malaysia", "Singapore", "Indonesia"]
countries[3]
countries[2]
countries[0]
countries[1]
countries[4]
Given the following array
var numbers = [752, 363, 587, 423, 688, 999]
What is the index of the number 999
(a)
Which of these lines of code will give you the number of elements in the numbers array?
numbers.value
numbers.innerHTML
numbers.length
Fill in the Blanks to allow the code to display an alert message for all the cars in the array
var cars = [“Saab”, “Volvo”, “BMW”];
for (var x = 0; x < cars.length; x++)
alert(cars[_______]);
cars
x
y
length
Given the following object:
var person = {
fn: “Raymond”,
ln: “Chia”,
age: 25 };
Which code will retrieve the value "Chia"
person[1]
person["ln"]
person.age
person.fn
Given the following array:
var person = ["Raymond", "Chia", "25"]
Which code will retrieve the value "Chia"?
person[1]
person["ln"]
person.age
person.fn
You retrieve values from objects by passing in the (a) of the value into the [ ]
You retrieve values from arrays by passing in the (a) of the value into the [ ]
Which of the following will remove the last element from an array and return the value?
push()
pop()
shift()
Which of these ways of creating a new Array is valid?
var x = ["A", "B", "C"];
var x = new Array["A", "B", "C"];
var x = (A", "B", "C");
var x = new Array("A", "B", "C");
Which of the following will add a new element to the end of the array?
push()
pop()
shift()
