CSP Unit 7 Parameters, Return, and
Libraries Assessment Exam Questions With
Revised Answers
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;
}
} - answer✔✔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();
, ©THEBRIGHTSTARS 2024
// 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)? - answer✔✔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<numList.length; i++){
if(numList[i] % 3 == 0){
numList[i] = numList[i] + addNum;
} else {
numList[i] = numList[i] - subtractNum;