No student devices needed. Know more
26 questions
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;
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)?
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]
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)
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
listAverage() returns the average number in a list. Which of these functions does this correctly?
What is printed to the console?
console.log(15 % 4);
2
3
4
1
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
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
OPTION A
OPTION B
OPTION C
OPTION D
This function finds the minimum number in a list. What should <MISSING CODE SEGMENT> be replaced with in order for this function to operate as expected?
function min(numList){
var min = numList[0];
for(var i=0; i<numList.length; i++){
if(numList[i] < min){
<MISSING CODE SEGMENT>
}
}
return min;
}
numList[i] = min;
min = numList[i];
min = numList;
numList = min;
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
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
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
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);
Dividing a program into separate subprograms (such as libraries) is known as:
modularity
iteration
API
documentation
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.
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.
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.
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
What is another word for a function?
function
command
abstraction
to call
If I want to make a function I must add parameters.
True
False
How many parameters can I add to a function.
1
2
3
as many as you would like
Parameters are different than arguments
True
False
What will print to the console after running this code segment?
15
16
21
18
What are the benefits of writing functions that use parameters and return? Try to list at least two.
What is the answer to
5 mod 2
3
2
1
0
Explore all questions with a free account