wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSP 2020 Midterm Review

Total questions: 16

Worksheet time: 16mins

Name
Class
Date
1.

Programs written with functions run more quickly

a)

True

b)

False

2.

Functions can help remove repeated code from a program

a)

True

b)

False

3.

Replacing repeated code with a function will reduce the number of commands the computer needs to run

a)

True

b)

False

4.

Functions are called once but can be declared many times

a)

True

b)

False

5.

Which of the following describes a conditional statement?

a)

affects the sequential flow of control by executing different statements based on the value of a Boolean expression

b)

stores information as a number, String, or Boolean

c)

joins together two or more strings end-to-end to make a new string

d)

an ordered sequence of characters

6.

Which of the following describes a variable?

a)

affects the sequential flow of control by executing different statements based on the value of a Boolean expression

b)

stores information as a number, String, or Boolean

c)

joins together two or more strings end-to-end to make a new string

d)

an ordered sequence of characters

7.

Which of the following describes concatenation?

a)

affects the sequential flow of control by executing different statements based on the value of a Boolean expression

b)

stores information as a number, String, or Boolean

c)

joins together two or more strings end-to-end to make a new string

d)

an ordered sequence of characters

8.

Consider the code segment below:

var a = 0;

var b = 3;

var c = 4;

a = a+c;

b = a+c;

c = a+c;


What are the values of a, b & c after this code segment has been run?

a)

a: 4 b: 4 c: 4

b)

a: 4 b: 8 c: 8

c)

a: 4 b: 8 c: 16

d)

a: 0 b: 3 c: 4

9.

Jan is writing a shopping app. She has created a variable to keep track of the number of items in the shopping cart. Every time someone clicks the "addItemButton" she wants the variable to increase by 1.

var cartTotal = 0;

onEvent("addItemButton", "click", function(){

//<missing code>

console.log(cartTotal);

});


What code should Jan insert where it says <missing code> in order for her app to work?

a)

cart Total = 1;

b)

cartTotal + 1;

c)

cartTotal = cartTotal + 1;

d)

var cartTotal = cartTotal + 1;

e)

var cartTotal + 1;

10.

What is the output to the console after the following code segment is executed?

fiveMore();


function fiveMore(){

var x = 5;

}


var y = 3 + x;

console.log(y);

a)

-2

b)

3

c)

5

d)

8

e)

Error. Unknown Identifier: x

11.

Consider the following flow chart. Given that a = 5 and b = 10, what will be displayed by the program? (click on the image if it doesn't show up)

a)

a is bigger

b)

b

c)

5

d)

10

e)

Nothing will be displayed

12.

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

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. (click on the image if it doesn't show)

a)

day == "Saturday"

b)

day == "Sunday"

c)

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

d)

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

e)

day != "Monday"

14.

Something is wrong with the logic in the program. For which values of time will the greeting “Good Morning!” be displayed?

a)

Any time between 6 and 9

b)

Any time between 10 and 19

c)

Any time between 0 and 20

d)

There is no value of time that will result in “Good Morning!” being displayed

e)

The logic error will cause the program to stop running at line 7.

15.

Choose the two (2) Boolean expressions that evaluate to FALSE.


var temperature = 30;

a)

(temperature > 0) && (temperature < 32)

b)

(temperature == 0) || (temperature < 32)

c)

(temperature != 0) && (temperature < 32)

d)

(temperature == 0) || (temperature > 32)

e)

(temperature < 0) || (temperature > 32)

16.

What is the correct way to call this function?


function numbers ( ) {

console.log("1,2,3,4,5");

}

(a)