Close
Close full mode
logoMakeCode AP CSP

Arrays Work

Activity

Go to Activity: Arrays Intro. Complete student tasks 1-2.

Tasks

Task 1

  1. Add two more numbers to the array, by pressing theβ€―+β€―button on the block.
  2. Change theβ€―get value atβ€―block to choose a random index between 0 and 3.
  3. Add another number to the array.
  4. Comment your code.

Shared project link:


Task 1 Challenge

Modify your code to randomly splash any new values added to the array.

Shared project link:


Task 2

  1. Create a new project called addingToAnArrayEvent.
  2. Create a new array with the values -3, 3, and 4.
  3. Create an on A button press event that adds a random number between -10 and 10 to the array.
  4. Create an on B button press event that selects a random item from the list and splash it.
  5. Comment your code.

Shared project link:


Task 2 Challenge

Modify the value of the splash to display the result of adding two random values from the list.

Shared project link:


Extension

Use JavaScript or Python to create the project above.

Shared project link:


Apply

Incorporate these concepts into an existing project.

Shared project link:


Reflection/Homework

  1. What is the difference between creating an array of numbers and storing multiple values as individual variables (as in, value1 = 1, value2 = 2, value3 ...)?

  2. What can an array do that storing different variables by themselves cannot?

  3. How does the length of an array relate to the position of the final element?

πŸ“˜ Unit 5 - AAP Part 2 β€” Previous
Arrays
Next β€” πŸ“˜ Unit 5 - AAP Part 2
Student Tasks/Solutions