Font size
WorksheetsJavascript Lists Lecture Knowledge Check
Total questions: 11
Worksheet time: 16mins
Which of the following is TRUE about lists.
They can't change size
They can only hold numbers
The order of items is not kept
Lists can be stored in a variable
In a list each item is assigned a number in that list. That number is called the ________?
location
index
identifier
list code
given the list
var names = ["Ann", "Bob", "Chuck", "Dana"];
which name is at names[2]?
Ann
Bob
Chuck
Dana
given
var nums = [3, 4, 6, 2, 9, 1];
what is
nums[1] + nums[3]
4
5
6
9
given the list
var names = ["Ann", "Bob", "Chuck", "Dana"];
how would I replace "Bob" with "Bill"?
names["Bob"] = "Bill";
list[1] = "Bill";
names[1] = "Bill";
names[2] = "Bill";
What would be the output of the following code?
var myList = ["A", "B", "C"];
console.log(myList.length);
2
3
4
If I had a list in my program called todo. While running lots of items are added to the end of the list. How can I get the last item in the list.
todo[last]
todo[todo.length]
todo.length - 1
todo[todo.length - 1]
what is in myNumbers after the following code runs.
var myNumbers = [10,20,25];
myNumbers[0] = 5;
myNumbers[2] = 30;
[10,20,25]
[5,20,25]
[5,20,30]
[5,10,20,25,30]
var myStuff = [20, “hat”, “pow”, 5];
myStuff[1] = “cat”;
myStuff[2] = myStuff[1];
myStuff[0] = myStuff[3] + 10;
myStuff[3] = myStuff[0] + myStuff[0];
["cat10", “hat”, “cat10cat10”, 5]
[15, “cat”, “hat”, 40]
[15, “cat”, “cat”, 30]
[15, “hat”, “pow”, 30]
var i = 1;
var nums = [3,2,1,5];
var x = (nums[ i + 1]) + (nums[i] + 1);
What is the value of x?
(a)
Consider the following code assuming that list1 starts as an empty list
APPEND(list1, 3);
APPEND(list1, 5);
APPEND(list1, 2);
INSERT(list1, 2, 4);
list1[3] ← 7;
REMOVE(list1,2);
What will be the contents of the list after the above operations?
3,5,7
7,5,2,2,4
3,7,2
3,7,4,5
