Search Header Logo

AP CSP Unit 5

Authored by Coral Riley

Computers

8th - 12th Grade

Used 77+ times

AP CSP Unit 5
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Consider the JavaScript code segment below. Which statement should be used in place of <missing code> such that the alarm is set to 9:00 am on weekends, and 6:30 am on weekdays.

var day = prompt("What day is it tomorrow?");

if ( <missing code> ){

setAlarm = "9:00am";

}

else {

setAlarm = "6:30am";

}

day == "Saturday"

day == "Sunday"

(day == "Saturday") || (day == "Sunday")

(day == "Saturday") && (day == "Sunday")

2.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Media Image

After running the following code segment, what is contained in the array data?

[3, 1, 8, 4, 4]

[2, 3, 4, 5, 6]

[2, 3, 4, 5, 4]

[3, 1, 8, 4 null]

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Choose the best description of what the mystery procedure below does.

PROCEDURE mystery (list, n)

{

i = 1

REPEAT LENGTH(list) TIMES

{

IF ( list[i] = n )

{

DISPLAY (i)

}

i = i+1

}

}

Mystery displays the number at index n.

Mystery displays the index of the first occurrence of the value n in the list.

Mystery displays the index of the last occurrence of the value n in the list.

Mystery displays the index of every occurrence of the value n in the list.

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Which of the following best describes the value returned by the procedure below?

PROCEDURE mystery (data)

{

count = 0

i = 1

REPEAT UNTIL (i = LENGTH(data))

{

IF (data[i] < data[i+1])

{

count = count + 1

}

i = i+1

}

RETURN (count)

}

The answers below refer to values being in ascending and descending order. Ascending order means increasing, as in: [1, 2, 5, 8]. Descending order means decreasing, as in [20, 15, 7, 3].

The procedure returns true when data is in ascending order

The procedure returns false when data is in descending order

The procedure returns the number of times adjacent items are in ascending order

The procedure returns how long it takes to find two numbers in ascending order

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Media Image

A robot starts in a grid facing north (B3). What is the robot's location and direction after the following program is executed?

data = ["F", "F", "R", "F", "L", "F", "R", "R", "F"]

FOR EACH move IN data

{

IF ( move = "F" AND CAN_MOVE(forward) )

{

MOVE_FORWARD()

}

ELSE IF (move = "R"){

rotate_right()

}

ELSE IF ( move = "L") {

rotate_left()

}

}

Media Image
Media Image
Media Image
Media Image

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?