Looks like no one added any tags here yet for you.
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;
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)?
function solveMaze(){
moveForward();
moveForward();
rotateRight();
while(canMove("forward")){
moveForward();
}
rotateLeft();
moveForward();
}
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
[0, 3, 6, -1, 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, 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
listAverage() returns the average number in a list. Which of these functions does this correctly?
function listAverage(list) {
var sum = 0;
for (var i = 0; i < list.length; i++) {
sum = sum + list[i];
}
return sum / list.length;
}
What is printed to the console?
console.log(15 % 4);
3
Which of the following is not true about procedural abstraction?
Procedural abstraction improves the speed at which a program executes.
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
OPTION C
This function finds the minimum number in a list. What should
function min(numList){
var min = numList[0];
for(var i=0; i
}
}
return min;
}
min = numList[i];
Algorithms can be created in all the following ways except:
Removing sequencing, selection, and iteration from an algorithm.
Using existing algorithms as building blocks for new algorithms has all the following benefits except:
Removes procedural abstraction.
What is one of the benefits of using a library in a program?
Simplifies creating a complex program.
Which call of the function correctly follows the instructions laid out in the API?
// moves a given element on the screen
// id (string) - the element ID for the item to be moved
// direction (string) - the direction the element should be moved
// amount (number) - the amount of pixels the element should be moved
function moveElement(id, direction, amount) {
var xPosition = getXPosition(id);
var yPosition = getYPosition(id);
if (direction == "left") {
setProperty(id, "x", xPosition - amount);
} else if ((direction == "right")) {
setProperty(id, "x", xPosition + amount);
} else if ((direction == "up")) {
setProperty(id, "y", yPosition - amount);
} else {
setProperty(id, "y", yPosition + amount);
}
}
moveElement("button1", "down", 25);
Dividing a program into separate subprograms (such as libraries) is known as:
Modularity.