Close
Close full mode
logoMakeCode AP CSP

Logic in Loops Activity

Activity

Go to Activity: Logic in Loops. Complete student tasks 1-2.

Tasks

Task 1

  1. Guessing Game Mod
  2. Using the Generate a second random value between 1 and 5, stored in secondValue.
  3. Change splash to β€œAnswer the question!”
  4. Compare guess to the result of value + secondValue.
  5. Change ask for string to ask for the sum of value and secondValue.
    • Include what those two values are in the message.
  6. Comment your code.

Shared Project Link:

Task 2

  1. Review the code segment in Sample #2 and examine what the game is missing to work properly.
  2. Code a single fireball to fire from mySprite in when A is pressed:
  3. Use if to check that the player has more than one life.
  4. Create a projectile of a fireball from mySprite (w/vx & vy).
  5. Decrease life by 1.
  6. Increase score by 1.
  7. Replace the if statement with a while loop, so that the projectiles continue until the player is out of life.
  8. Comment your code.

Shared Project Link:

Extension

Use functions and parameters to make the fireball game easier to manage.

Shared Project Link:

Extension

Use JavaScript or Python to create this project.

Shared Project Link:

Reflection/Homework

  1. How are While loops different from For loops?

  2. Explain why picking up the fireSource allowed the player to keep making fireballs, without any other buttons being pressed.

  3. Challenge: If "IF statements" didn’t exist, could you use While loops to implement the same behavior in blocks? If so, how?

πŸ“˜ Unit 5 - AAP Part 2 β€” Previous
Sentence Puzzles
Next β€” πŸ“˜ Unit 5 - AAP Part 2
Student Tasks/Solution