wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Javascript Lists Lecture Knowledge Check

Total questions: 11

Worksheet time: 16mins

Name
Class
Date
1.

Which of the following is TRUE about lists.

a)

They can't change size

b)

They can only hold numbers

c)

The order of items is not kept

d)

Lists can be stored in a variable

2.

In a list each item is assigned a number in that list. That number is called the ________?

a)

location

b)

index

c)

identifier

d)

list code

3.

given the list

var names = ["Ann", "Bob", "Chuck", "Dana"];

which name is at names[2]?

a)

Ann

b)

Bob

c)

Chuck

d)

Dana

4.

given

var nums = [3, 4, 6, 2, 9, 1];

what is

nums[1] + nums[3]

a)

4

b)

5

c)

6

d)

9

5.

given the list

var names = ["Ann", "Bob", "Chuck", "Dana"];

how would I replace "Bob" with "Bill"?

a)

names["Bob"] = "Bill";

b)

list[1] = "Bill";

c)

names[1] = "Bill";

d)

names[2] = "Bill";

6.

What would be the output of the following code?


var myList = ["A", "B", "C"];

console.log(myList.length);

a)

2

b)

3

c)

4

7.

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.

a)

todo[last]

b)

todo[todo.length]

c)

todo.length - 1

d)

todo[todo.length - 1]

8.

what is in myNumbers after the following code runs.

var myNumbers = [10,20,25];

myNumbers[0] = 5;

myNumbers[2] = 30;

a)

[10,20,25]

b)

[5,20,25]

c)

[5,20,30]

d)

[5,10,20,25,30]

9.

var myStuff = [20, “hat”, “pow”, 5];      
myStuff[1] = “cat”;                                  
myStuff[2] = myStuff[1];                       
myStuff[0] = myStuff[3] + 10;              
myStuff[3] = myStuff[0] + myStuff[0];

a)

["cat10", “hat”, “cat10cat10”, 5]

b)

[15, “cat”, “hat”, 40]

c)

[15, “cat”, “cat”, 30]

d)

[15, “hat”, “pow”, 30]

10.

var i = 1;

var nums = [3,2,1,5];

var x = (nums[ i + 1]) + (nums[i] + 1);

What is the value of x?

(a)  

11.

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?

a)

3,5,7

b)

7,5,2,2,4

c)

3,7,2

d)

3,7,4,5