Computers

9th -

12thgrade

Image

AP CSP Unit 7: Parameters, Returns, and Libraries

1.4K
plays

26 questions

Show Answers
See Preview
  • 1. Multiple Choice
    2 minutes
    1 pt

    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;

  • 2. Multiple Choice
    2 minutes
    1 pt
    Image

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

    Image
    Image
    Image
    Image
  • 3. Multiple Choice
    2 minutes
    1 pt
    Image

    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]

  • Answer choices
    Tags
    Answer choices
    Tags

    Explore all questions with a free account

    Already have an account?