CS Grade 6-8

CS: Block-Based Programming: Events and Conditionals

Using events to start code and conditions to choose actions

View Answer Key
Name:
Date:
Score: / 15

Using events to start code and conditions to choose actions

CS - Grade 6-8

Instructions: Read each problem carefully. Use clear explanations and write block steps in order when asked.
  1. 1

    In block-based programming, what is an event? Give one example of an event that could start a script.

  2. 2
    A blank keyboard key triggers a sprite to jump upward.

    A sprite should jump when the player presses the space key. Which event block would best start this script, and what action block could come after it?

  3. 3

    A program has this condition: if score > 10, then show the message 'Level up'. If the score is 8, will the message appear? Explain.

  4. 4
    A sprite becomes happy when touching a star and neutral when not touching it.

    Write the logic for an if-else block that changes a sprite to the 'happy' costume if it is touching a star, and changes it to the 'normal' costume otherwise.

  5. 5
    A green flag starts a sprite moving right while a loop continues.

    A script says: when green flag clicked, forever, if right arrow key pressed, change x by 5. Describe what the sprite does while the program runs.

  6. 6
    A sprite repeatedly checks the edge and bounces away.

    A student puts this code under when green flag clicked: if touching edge, then bounce. The sprite only checks once at the start. What block should the student add so the sprite keeps checking for the edge?

  7. 7
    One sprite has two separate scripts: click to play sound and key press to move up.

    A sprite has two scripts. One script starts when the sprite is clicked and plays a sound. Another script starts when the up arrow key is pressed and moves the sprite up. Can both scripts be used in the same project? Explain.

  8. 8

    A weather app uses conditionals. If raining is true, it shows 'Bring an umbrella'. Else, it shows 'No umbrella needed'. What message appears when raining is false?

  9. 9
    A sprite collects a coin, the score increases, and the coin hides.

    Design a short block-based plan for collecting a coin. When the player touches the coin, the score should increase by 1 and the coin should hide.

  10. 10

    A game has lives = 3. The code says: if lives = 0, then broadcast game over, else keep playing. What happens when lives equals 3?

  11. 11
    A shield protects a player sprite from an enemy collision.

    A condition says: if touching enemy and shieldOn = false, then lose 1 life. The player is touching an enemy, but shieldOn = true. Does the player lose a life? Explain.

  12. 12

    A start button sprite should begin the game when clicked. Write two actions that could happen after the event 'when this sprite clicked'.

  13. 13
    Two branching diagrams compare a single-action condition and a two-path condition.

    Explain the difference between an if block and an if-else block.

  14. 14
    A maze sprite touches a wall and returns to the start inside a repeated loop.

    A maze game uses this logic: when green flag clicked, forever, if touching wall, go back to start. Why is the if block placed inside the forever loop?

  15. 15
    A sprite moving right stops at a boundary near the edge of the stage.

    A sprite should stop moving right when its x position is greater than 220. Write a conditional rule that would help control this movement.

LivePhysics™.com CS - Grade 6-8

More CS Worksheets

See all CS worksheets

More Grade 6-8 Worksheets

See all Grade 6-8 worksheets