CSP Unit 7 Parameters, Return, and Libraries Assessment

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 14

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

15 Terms

1

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;

New cards
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)?

function solveMaze(){

moveForward();

moveForward();

rotateRight();

while(canMove("forward")){

moveForward();

}

rotateLeft();

moveForward();

}

New cards
3

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]

New cards
4

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)

New cards
5

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

New cards
6

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;

}

New cards
7

What is printed to the console?

console.log(15 % 4);

3

New cards
8

Which of the following is not true about procedural abstraction?

Procedural abstraction improves the speed at which a program executes.

New cards
9

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

New cards
10

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

function min(numList){

var min = numList[0];

for(var i=0; i

}

}

return min;

}

min = numList[i];

New cards
11

Algorithms can be created in all the following ways except:

Removing sequencing, selection, and iteration from an algorithm.

New cards
12

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

Removes procedural abstraction.

New cards
13

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

Simplifies creating a complex program.

New cards
14

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);

New cards
15

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

Modularity.

New cards

Explore top notes

note Note
studied byStudied by 6 people
888 days ago
5.0(1)
note Note
studied byStudied by 13 people
330 days ago
5.0(1)
note Note
studied byStudied by 4 people
839 days ago
5.0(1)
note Note
studied byStudied by 1 person
809 days ago
5.0(1)
note Note
studied byStudied by 1 person
58 days ago
5.0(1)
note Note
studied byStudied by 8 people
788 days ago
5.0(1)
note Note
studied byStudied by 165 people
115 days ago
4.0(1)

Explore top flashcards

flashcards Flashcard (37)
studied byStudied by 16 people
792 days ago
4.7(3)
flashcards Flashcard (130)
studied byStudied by 3 people
672 days ago
5.0(1)
flashcards Flashcard (49)
studied byStudied by 4 people
120 days ago
5.0(1)
flashcards Flashcard (88)
studied byStudied by 170 people
547 days ago
5.0(3)
flashcards Flashcard (57)
studied byStudied by 1 person
29 days ago
5.0(2)
flashcards Flashcard (77)
studied byStudied by 8 people
493 days ago
5.0(1)
flashcards Flashcard (24)
studied byStudied by 3 people
833 days ago
5.0(1)
flashcards Flashcard (163)
studied byStudied by 185 people
421 days ago
5.0(1)
robot