Logic in Loops Activity
Activity
Go to Activity: Logic in Loops. Complete student tasks 1-2.
Tasks
Task 1
- Guessing Game Mod
- Using the Generate a second random value between 1 and 5, stored in secondValue.
- Change splash to βAnswer the question!β
- Compare guess to the result of value + secondValue.
- Change ask for string to ask for the sum of value and secondValue.
- Include what those two values are in the message.
- Comment your code.
Shared Project Link:
Task 2
- Review the code segment in Sample #2 and examine what the game is missing to work properly.
- Code a single fireball to fire from mySprite in when A is pressed:
- Use if to check that the player has more than one life.
- Create a projectile of a fireball from mySprite (w/vx & vy).
- Decrease life by 1.
- Increase score by 1.
- Replace the if statement with a while loop, so that the projectiles continue until the player is out of life.
- 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
How are While loops different from For loops?
Explain why picking up the fireSource allowed the player to keep making fireballs, without any other buttons being pressed.
Challenge: If "IF statements" didnβt exist, could you use While loops to implement the same behavior in blocks? If so, how?