wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSP Code.org Unit 7

Total questions: 65

Worksheet time: 47mins

Name
Class
Date
1.

Cutting a big program up into smaller subprograms (functions, procedures, etc)

a)

modularity

b)

procedural abstraction

2.

In computer programming, this allows you to use a function knowing WHAT it does but not necessarily HOW it does it.

a)

modularity

b)

procedural abstraction

3.

Directions for how a collection of functions behave and can be used

a)

Library

b)

API

4.

A group of functions (procedures) that may be used in creating new programs

a)

library

b)

API

5.
a)

the orange x is a parameter

b)

the orange x is an argument

6.

a)

the "7" is a parameter

b)

the "7" is an argument

7.

a)

the variable "y" on line 2 is a parameter

b)

the variable "y" on line 2 is an argument

8.

a)

the variable "year" in function getYear(year)

is a parameter

b)

the variable "year" in function getYear(year)

is an argument

9.

a variable used as a place holder for a value passed to a function

a)

parameter

b)

argument

10.

a value passed to a function

a)

parameter

b)

argument

11.
a)

<MISSING CODE> should be:

x % 2 == 0

b)

<MISSING CODE> should be:

x % 2 == 1

c)

<MISSING CODE> should be:

x % 1 == 0

d)

<MISSING CODE> should be:

x % 1 == 2

e)

<MISSING CODE> should be:

x % 1 == 1

12.

a)

0

b)

5

c)

4

d)

0.2

13.
a)

3

b)

3.75

c)

0.267

d)

0

14.

a)

1

b)

2.14

c)

2

d)

0.41

15.
A variable with local scope is one that can only be seen, used and updated by code within the same scope. Typically this means the variable was declared (created) inside a function -- includes function parameter variables. 
a)
Local variable
b)
Home variable
c)
Common variable
d)
Global variable
16.
Dictates what portions of the code can "see" or use a variable, typically derived from where the variable was first created. (See Global v. Local)
a)
Variable Scope
b)
Variable View
c)
Variable Protocol
d)
Variable Interface
17.

In the above picture, this would be an example of a:

a)

Local Variable

b)

Nested Variable

c)

Global Variable

d)

Variable Scope

18.

In the above picture, this would be an example of a:

a)

Local Variable

b)

Nested Variable

c)

Global Variable

d)

Variable Scope

19.

A variable whose scope is "global" to the program, it can be used and updated by any part of the code. Its global scope is typically derived from the variable being declared (created) outside of any function, object, or method.

a)

Global Variable

b)

Local Variable

c)

Wide Variable

d)

Limited Variable

20.

A variable with local scope is one that can only be seen, used and updated by code within the same scope. Typically this means the variable was declared (created) inside a function -- includes function parameter variables.

a)

Short Variable

b)

Small Variable

c)

Global Variable

d)

Local Variable

21.

A function must always have parameters in order for it to work.

a)

True

b)

False

22.

A function must have a return value in order for it work properly.

a)

True

b)

False

23.

A function can have a parameter(s) but not necessarily have a return value.

a)

True

b)

False

24.

A function can have a return value but not necessarily have any parameters.

a)

True

b)

False

25.

Which of the following is FALSE regarding functions?

a)

(a) Functions with parameters and return values help us simplify our code

b)

(b) A function can have parameters, but no return values

c)

(c) A function can return multiple values at one time

d)

A, B, C are all false

26.

Look at this code. Which of the following will be shown in the console log when this program is ran?

a)

This line always runs

b)

This line always runs

But this one never does

c)

But this one never does

d)

Nothing will run in the console log

27.

A function is also known as a procedure

a)

True

b)

False

28.

An argument can include:

a)

(a) a number

b)

(b) a string

c)

Both A and B

d)

Neither A or B

29.

Which of the following is FALSE regarding return values?

a)

(A) It stops the flow of the function

b)

(B) If a return is inside of a conditional, if that condition is met the function ends there.

c)

(C) It returns a value to the place where the function was called.

d)

None of these (A, B, C are all True)

30.

A function return value can never be stored inside a variable.

a)

True

b)

False

31.

Parameters and return values allow you to write programs that are more organized and cleaner.

a)

True

b)

False

32.

Look at this code. Which of the following will be shown in the console log when this program is ran?

a)

10

20

1000

b)

10

c)

1000

d)

Nothing will run in the console log

33.

Generally it is up to you (as the programmer) to decide how a returned value will be used in the rest of your program.

a)

True

b)

False

34.

Which of the following is FALSE regarding guidelines you should follow in writing functions with return values?

a)

(1) Decide what values you need as input to your computation. Make these parameters of your function.

b)

(2) Use your parameters to calculate your result and save that result in a single variable.

c)

(3) Return that variable outside of this function

d)

All three of these are True

35.

In the example above, we say that lives is a local variable.

a)

True

b)

False

36.

We say that function parameters are a form of a local variable because (choose all that apply):

a)

they get created and initialized when a function is called

b)

they get used while the function runs

c)

they get destroyed when the function completes

d)

they can be used both inside and outside of a given function

37.

One of the disadvantages of writing functions that use parameters and return values is that it repeats code multiple times making your program disorganized and not very clean.

a)

True

b)

False

38.

Once functions are written that take parameters and return values, it's easier to reuse that code in other places of your program.

a)

True

b)

False

39.

Looking at this image, which of the following would be considered a parameter for the function totalCost?

a)

total

b)

check

c)

cost

d)

There are no parameters for this function

40.

The function move(id, direction) could be used to move an element in any direction, rather than writing separate functions for each direction. This is considered an example of:

a)

Modularity

b)

Procedural Abstraction

c)

Library

d)

API

41.

What will print to the console after running this code segment?

a)

10

b)

60

c)

54

d)

56

42.

What is printed to the console log?


console.log (12 % 3);

a)

4

b)

3

c)

0

d)

2

43.

A library should have all of the following documentation EXCEPT:

a)

(A) how each function works

b)

(B) a complete list of the arguments

c)

(C) what (if anything) will be returned

d)

A, B, C should all be included

44.

Looking at the above documentation here, what else should be included here (in place of the question marks)?

a)

number

b)

string

c)

list

d)

Can be either number, string, or list (depends)

45.

In Lesson 7 you answered we discussed potential problems that could come up if you tried to use a function without knowing what it does or how to interact with it. Those included all of the following EXCEPT:

a)

Guessing what value is returned

b)

Determining what argument(s) your function needs

c)

Knowing what the function does

d)

Finding an error when you run the code when the function is called

46.

Before adding a function to a library, check for any use of a local variables within the function. If there is, rework the function using global variables and a return.

a)

True

b)

False

47.

Before adding a function to a library, check if another function is called in this function. If so, both functions should be included in the library.

a)

True

b)

False

48.

When creating a library (check all that apply):

a)

Same as functions; do not start with a Capital Letter

b)

Same as a function; no spaces in the library name

c)

"Library" must be included in the name

d)

Include what type of value the return and/or parameter has (ex. string)

49.

As a user, what information would you need to know in order to use a particular library function?

a)

You need to know the documentation for the functions so you can call them correctly and understand what will be returned

b)

You need to know how the traversal looks in the function

c)

You must know what arguments are used

d)

You have to know what the coding looks like for the entire function

50.

One benefit of hiding all of the code when filtering the dataset in a library would be that it makes your coding organized and neat.

a)

True

b)

False

51.

What are the benefits of using existing algorithms instead of brand new algorithms (check all that apply)?

a)

reduced development time

b)

reduced testing

c)

simplification and identification of errors

52.

When we organize functions into a library and then call them in another program, we are really practicing this (check all that apply):

a)

Modularity

b)

API

c)

Library

d)

Procedural Abstraction

53.

What is the output of the following program?

a)

5

15

b)

15

5

c)

nothing will print

d)

5

54.

What is printed by the following program?

a)

-7

b)

7

c)

=13

d)

13

55.

What will be printed to the screen when the following program is run?

function start(){

println(doubleNumber(doubleNumber(10)));

}

function doubleNumber(x){

var doubledX = 2 * x;

return doubledX;

}

a)

20

b)

100

c)

40

d)

x

56.

In the following function printThreeTimes:

function printThreeTimes(word){

println(word);

println(word);

println(word);

}

What is the parameter of the function?

a)

word

word

word

b)

word

c)

no parameter

d)

println

57.

What is the minimum number of parameters that must be given when calling the ‘drawCircle’ function?

function drawCircle(radius, x, y, color) {

var circle = new Circle(radius);

circle.setPosition(x, y);

circle.setColor(color);

add(circle);

}

a)

1

b)

2

c)

0

d)

4

58.

// This function prints out the area of a rectangle given its base and height function rectangleArea(base, height){

var area = base * height;

println(area);

}

What are the names of the parameters?

a)

base and height

b)

length and width

c)

var area

d)

println(area)

59.

What is printed by the program?

a)

2

1

0

b)

two

one

zero

c)

nothing will print

d)

0

1

2

60.

How many parameters go into the function sum, and how many return values come out of the function sum

function sum(first, second, third){

var result = first + second + third;

println(first);

println(second);

println(third);

return result;

}

a)

3 parameters go in,

1 return value comes out

b)

3 parameters go in,

3 return value comes out

c)

No parameters go in

d)

No result comes out

61.

Look at the screenshot. Examples of arguments would include (click all that apply):

a)

Laquan

b)

name

c)

October

d)

birthMonth

62.

Look at the screenshot. Examples of parameters would include (click all that apply):

a)

age

b)

Lenora

c)

March

d)

birthMonth

63.

Look at the screenshot. An example of a return that could take place in this function would be 12

a)

True

b)

False

64.

Look at the screenshot. In order to rewrite this program to include parameters for the "searchTypeList" function, would could eliminate:

a)

Just the global variable "typeInput"

b)

Just the global variable "ratingInput"

c)

Both global variables "typeInput" and "ratingInput"

65.

Look at the screenshot. In order to eliminate the global variable called "selection", one solution would be to add a parameter to the "checkAnswer" function.

a)

True

b)

False