a Flashcards

1
Q

Which code segment results in “true” being returned if a number is even? Replace “MISSING CONDITION” with the correct code segment.
function isEven(num){
if(MISSING CONDITION){
return true;
} else {
return false;
}
}

num % 2 == 0;
num % 0 == 2;
num % 1 == 0;
num % 1 == 2;

A

a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Here is the API for a robot library.
// moves the robot forward
function moveForward();

// turns the robot to the left
function rotateLeft();

// turns the robot to the right
function rotateRight();

// checks if a robot can move in any direction
// direction {string} - the direction to be checked
// return {Boolean} - true if the robot can move in that direction, otherwise returns false
function canMove(direction);

Which code segment will guarantee that the robot makes it to the gray square without hitting a wall or a barrier (black square)?

A

forward, forward, right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What will be printed to the console after this program runs?

var numbers = [2, 5, 3, 1, 6]

function changeNums(numList, addNum, subtractNum){
for(var i=0; i<numList.length; i++){
if(numList[i] % 3 == 0){
numList[i] = numList[i] + addNum;
} else {
numList[i] = numList[i] - subtractNum;
}
}
}

changeNums(numbers, 3, 2);
console.log(numbers);

[2, 5, 3, 1, 6]
[0, 3, 6, -1, 9]
[-1, 2, 6, -2, 8]
[5, 2, 6, 3, 9]

A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which function calls would provide the most helpful test of this function?

Remember: With tests, you are attempting to figure out all the possible ways the function could be broken.

function findMin(num1, num2){
if(num1 < num2){
return num1;
} else {
return num2;
}

findMin(-1, 0)
findMin(2,4)
findMin(5,10)

findMin(5,3)
findMin(7,2)
findMin(5,1)

findMin(1,1)
findMin(-2,2)
findMin(0,3)

findMin(-1,1)
findMin(1,-1)
findMin(1,1)

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

You have imported a library with the birthMonth() function. Based on the API, how many strings are inputed to calculate the birth month?

// calculate birth month based on the day of the month, day of the week, and the birth year
// dayMonth {number} - a day of a month from 1 to 31
// dayWeek {string} - the name of the day of the week
// year {number} - the birth year
// return {string} - the month you were born
BirthdayLibrary.birthMonth(dayMonth, dayWeek, year);

1
4
0
3

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

listAverage() returns the average number in a list. Which of these functions does this correctly?

A

sum
}
return
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is printed to the console?

console.log(15 % 4);

2
3
4
1

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following is NOT true about procedural abstraction?

Procedural abstraction improves code readability

Procedural abstraction manages complexity by allowing for code reuse

Procedural abstraction improves the speed at which a program executes

Procedural abstraction allows a solution to a large problem to be based on the solution of smaller subproblems

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

This function checks if a character is a vowel. If it is, it returns true. Otherwise, it returns false.
Where should return false; be written in the code?

function checkVowel(character){
var vowels = [“a”, “e”, “i”, “o”, “u”];
for(var i=0; i<vowels.length; i++){
if(vowels[i] == character){
return true;
OPTION A
}
OPTION B
}
OPTION C
}
OPTION D

A

option c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

This function finds the minimum number in a list. What should <MISSING> be replaced with in order for this function to operate as expected?</MISSING>

function min(numList){
var min = numList[0];
for(var i=0; i<numList.length; i++){
if(numList[i] < min){

<MISSING>
}
}
return min;
}

numList[i] = min;

min = numList[i];

min = numList;

numList = min;
</MISSING>

A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Algorithms can be created in all the following ways EXCEPT:

creating from an idea

combining existing algorithms

removing sequencing, selection, and iteration from an algorithm

modifying existing algorithms

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Using existing algorithms as building blocks for new algorithms has all the following benefits EXCEPT:

reduces development time

reduces testing

simplifies debugging

removes procedural abstraction

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is one of the benefits of using a library in a program?

simplifies creating a complex program

increases development time

removes all testing

reduces abstractions in the program

A

a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which call of the function correctly follows the instructions laid out in the API?

moveElement(“button1”, 2, 23);

moveElement(“button1”, “left”, “thirty”);

moveElement(“button1”, 30, “two”);

moveElement(“button1”, “down”, 25);

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Dividing a program into separate subprograms (such as libraries) is known as:

modularity
iteration
API
documentation

A

a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Parameter

the value passed to the parameter

used to return the flow of control to the point where the procedure (also known as a function) was called and to return the value of expression.

Extracting shared features to generalize functionality

a variable in a function definition. Used as a placeholder for values that will be passed through the function.

17
Q

Argument

The subdivision of a computer program into separate subprograms

the value passed to the parameter

a variable in a function definition.
Used as a placeholder for values that will be passed through the function.

18
Q

Return

Extracting shared features to generalize functionality

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

The subdivision of a computer program into separate subprograms

used to return the flow of control to the point where the procedure (also known as a function) was called and to return the value of expression.

19
Q

Procedural abstraction

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

Extracting shared features to generalize functionality

The subdivision of a computer program into separate subprograms

Application Program Interface - specifications for how functions in a library behave and can be used

20
Q

another word for function

A

abstraction

21
Q

If I want to make a function I must add parameters.
True
False

22
Q

How many parameters can I add to a function.

A

as many as you would like

23
Q

Parameters are different than arguments
True
False

24
Q

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

15
16
21
18

25
What is the answer to 5 mod 2 3 2 1 0
1
26
What are the benefits of writing functions that use parameters and return?
readable code, reusable (can add without rewriting whole code)