Close
Close full mode
logoMakeCode AP CSP

Student Tasks/Solutions

Tasks

Task 1

  1. Create a function named greet.
  2. Add a parameter firstName that is of type string.
  3. In the function, splash a greeting that includes firstName (if β€œYou” is passed, it might splash β€œHey, You!”).
  4. Call the function with three different names.

parametersTask1

Task 2

  1. Start with your solution to task #1.
  2. Modify the function so that it accepts two strings: firstName and lastName.
  3. Make use of both parameters in the greeting (for example, greeting ("You", "Friend") could result in β€œHey You Friend!”).

parametersTask2

Task 3

  1. Create a function named horizontalMovement.
  2. Add two parameters to the function: player of type Sprite, and left of type Boolean.
  3. if left is true, move player 10 pixels to the left.
  4. if left is false, move player 10 pixels to the right.

parametersTask3

Extension:

Recreate the parameters tasks using JavaScript or Python.

Apply

Review your past projects for opportunities to use functions with parameters.

Reflection

  • How do parameters allow for more flexible code?
  • Review the functions you have learned, like splash and say, and identify which ones have parameters.
  • Where might parameters be used in your previous projects?

Homework

  • Complete the problem set at Problem Set: Parameters.
  • You may use block or text-based programming for the problem sets.
  • Comment your code as your work.

Solutions

  1. Urgent Message
  2. Caps Lock
  3. Pizza Place
  4. Sprite Factory
  5. Follow the Leader
πŸ“˜ Unit 5 - AAP Part 2 β€” Previous
Writing Functions with Parameters
Next β€” πŸ“˜ Unit 5 - AAP Part 2
Day 3