Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSP: Unit 5 Test Review - List, Loops, & Traversals

Total questions: 50

Worksheet time: 47mins

Name
Class
Date
1.
To repeat in order to achieve, or get closer to, a desired goal
a)
while loop
b)
Iterate
c)
Array
d)
List
2.
a programming construct used to repeat a set of commands (loop) as long as a boolean condition is true
a)
while loop
b)
Iterate
c)
Array
d)
List
3.
A generic term for a programming data structure that holds multiple items.
a)
while loop
b)
Iterate
c)
Array
d)
List
4.
A typical looping construct designed to make it easy to repeat a section of code using a counter variable.
a)
for loop
b)
While Loop
c)
Do While Loop
d)
iterate
5.
A value sent back by a function to the place in the code where the function was called form
a)
UI Handle
b)
Return String
c)
Return Value 
d)
Array
6.
in JavaScript an event triggered by pressing or releasing a key on the keyboard
a)

OnEvent

b)
UI Handle
c)
UI Interface
d)

Design Mode

7.
An action that causes something to happen
a)
UI Elements
b)
Event 
c)
Event listener
d)
User Interface
8.
A placeholder for a piece of information that can change
a)
Data Type
b)
Variable
c)
Expression
d)
Global Variable
9.
A variable whose scope is covers the whole program, it can be used and updated by any part of the code. Its scope is typically derived from the variable being declared (created) outside of any function, object, or method.
a)
Variable Scope
b)
Global Variable
c)
Expression
d)
Local Variable
10.
 A variable that can only be seen, used and updated by code within the same scope. Typically this means it was declared (created) inside a function -- includes function parameter variables.
a)
Variable Scope
b)
Global Variable
c)
Expression
d)
Local Variable
11.
 Any sequence of characters between quotation marks (ex: "hello", "42", "See you tomorrow")
a)
String
b)
Expression
c)
Variable
d)
Concatenate
12.
Typically used when joining together text in programming (e.g. "Hello, "+name)
a)
String
b)
Expression
c)
Variable
d)
Concatenate
13.

Consider the JavaScript code segment below. Which statement should be used in place of <missing code> such that the alarm is set to 9:00 am on weekends, and 6:30 am on weekdays.

var day = prompt("What day is it tomorrow?");

if ( <missing code> ){

setAlarm = "9:00am";

}

else {

setAlarm = "6:30am";

}

a)

day == "Saturday"

b)

day == "Sunday"

c)

(day == "Saturday") || (day == "Sunday")

d)

(day == "Saturday") && (day == "Sunday")

14.

What is an event-driven program?

a)

A program that does not implement algorithms

b)

A program in which all portions of the code will always be executed while it is running

c)

A program written to respond to specified events by executing a block of code of function associated with the event

d)

A program that can only be run once and only have one possible outcome, regardless of the user interactions.

15.

Which of the following is true about element IDs?

a)

An element with a unique ID must always have an event handler associated with it.

b)

An element that needs to be triggered by onEvent does not need a unique ID.

c)

Two or more onEvent calls may reference the same ID

d)

IDs cannot be referenced multiple times

16.

"You win!" never displays. What line is responsible for this error?

a)

1

b)

3

c)

4

d)

5

17.

Which of the following methods expects the new element as an argument and adds the new element to the end of the list?

a)

append

b)

expand

c)

insert

d)

search

18.

Which type of function usually tests its argument for the presence or absence of some property?

a)

return

b)

main

c)

Boolean

d)

square

19.

What is first index value of an array?

a)

-1

b)

0

c)

1

d)

undefine

20.
What surrounds an array?
a)
Quotations
b)
Curly Brackets
c)
Parenthesis
d)
Square Brackets
21.
array = [1,2,3,4,5]
What is the length of this array?
a)
5
b)
4
c)
0
d)
125.4
22.

What is proper syntax for declaring a array in JavaScript?

a)

var arrayName =[ ];

b)

var arrayName[ ] ={ };

c)

array arrayName ={ };

d)

obj var arrayName =[ ];

23.
array = [1,2,3,4,5];
What is the highest position in this array?
HINT: Remember arrays start at position 0!
a)
4
b)
5
c)
0
d)
125.7
24.
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
 System.out.println("Welcome to Java");
 count++;
}
a)
8
b)
9
c)
10
d)
0
25.

For this scenario related to turtle/robot drawing, indicate whether it is better to write a loop or a function (or a set of functions) to handle the task:


Drawing a hexagon (six-sided shape)

a)

Loop

b)

Function

26.

A Boolean expression is an expression that evaluates to which of the of the following?

a)

Yes/Maybe/No

b)

True/False

c)

Any Integer

d)

Integers between 1 and 10

e)

Any single character

27.

Which vocabulary word is:

a common method for referencing the elements in a list or string using numbers

a)

list

b)

element

c)

index

28.

Which vocabulary word is:

an ordered collection of elements

a)

list

b)

element

c)

index

29.

Match the index with the value.


var myNumbers = [32, 64, 33, 0, 15, 26, 3]

myNumbers[4]

a)

64

b)

15

c)

0

d)

32

30.

//Consider this code:

var list = [10, 12, 14, 16, 18];

appendItem(list, 3);

insertItem(list, 2, 20);

removeItem(list, 0);


//What is printed to the console?

console.log(list[0]);

(a)  

31.

//Consider this code:

var list = [10, 12, 14, 16, 18];

appendItem(list, 3);

insertItem(list, 2, 20);

removeItem(list, 0);


//What is printed to the console?

console.log(list.length);

(a)  

32.

//Consider this code.


var beginning = "My name is ";

var end = "Mrs. Anderson";

var sentence = beginning + end;


//What is printed to the console?

console.log(sentence.length);

a)

name

b)

name is

c)

y name

d)

23

e)

n

33.
a)

4

b)

7

c)

9

d)

10

e)

ab

34.

Which type of loop iterates until condition become False?

a)

FOR loop

b)

A count-controlled loop

c)

Repeat-once loop

d)

WHILE loop

35.

In a while loop the minimum time a code will be executed is

a)

Once

b)

Twice

c)

0

36.

A condition is

a)

a statement that is either True or False

b)

a string

c)

an integer

d)

a list

37.

What does the code output?

a)

0

1

2

3

b)

1

2

3

c)

0

1

2

38.

Print i as long as i is less than 6.

What will be the code?

a)

i = 1

while i < 6:

print(i)

i += 1

b)

i = 1

when i < 6;

print(i)

i += 1

c)

i = 1

i < 6:

print(i)

i += 1

39.

What is the output of the below Java code?

int score=1;

for(; true; score++)

{

System.out.print(score +",");

if(score > 3)

break;

}

a)

1,2,3,

b)

1,2,3

c)

1,2,3,4,

d)

1,2,3,4

40.

This loop can only be used when the programmer knows the number of times a code is to be repeated

a)

while

b)

for

c)

do while

d)

repeat until

41.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

42.

A school is developing a program to keep track of information about students and their class schedules. In which of the following instances would a data abstraction be most helpful?

a)

The program includes individual variables to store the names of each student rather than a single list of students.

b)

A program includes multiple comments that could be combined into a single comment

c)

A program includes repeated programming statements that could be moved inside a loop

d)

A program includes repeated code that could be moved inside a function

43.

Which of the following will result in ONLY all the items in list being printed to the console if placed where the program reads <INSERT CODE> and the program is run?

a)

i < list{list.length]

b)

i < list.length

c)

i < list[0]

d)

i < list [1]

44.

wordList is a list of words that currently contains the values

["tree", "rock", "air"]

Which of the following lines will result in the list containing the values ["air", "rock", "air"]

a)

wordList[0] = wordList [2]

b)

wordList[2] = wordList [0]

c)

insertItem (wordList, 0, "air")

d)

removeItem(wordList, 0)

45.

What will be displayed in the console when this program runs?

a)

2

b)

3

c)

20

d)

30

46.

What will be displayed when this program finishes running?

a)

3

b)

6

c)

7

d)

5

47.

What will the following program display in the console?

a)

0

1

2

3

b)

0

1

2

3

4

c)

1

2

3

d)

1

2

3

4

48.

What will the following program display in the console?

a)

0

b)

5

c)

10

d)

15

49.

If the program above is run, what will be displayed in the console?

a)

[apple, dream]

b)

[bug, car, ear]

c)

bug, car ear, food]

d)

[apple, dream, food]

50.

A restaurant knows from historical data that 60 out of 100 of its customers purchase a full meal while 40 out of 100 only order a side dish. The program above is intended to simulate the orders of 1000 customers.

Which of the following can be used to replace <MISSING CODE> so that the simulation works as intended?

a)

random(1,100) <= 60

b)

random(1,100) = 40

c)

random(1,100) <=40

d)

random(1,100) = 60