Year 7 · Y7.2 Programming Essentials in Scratch · Lesson 3

Stretch tasks Iteration and events

Task 1

Quiz Challenge

A quiz game against four computer players, then short and long written answers.

  1. Quiz Blitz12 questions against the clock
  2. Quick Fire4 short answers
  3. Big Think2 long answers

About 20 minutes

Task 2

This or That

Pixel the cat asks 8 questions. Each has two answers: pick the right one.

  • Two answers to every question
  • A fish treat for every right answer
  • Streaks win Pixel shades, then a party hat

About 4 minutes

Task 3

Memory Match

Flip the cards two at a time to match each term card to its meaning card.

  • 12 cards: each term has a meaning
  • One peek at every card
  • Combo points for pairs found in a row

6 pairs, about 4 minutes

The games need JavaScript. Every question is below, with the answers at the end.

Read the lesson: Iteration and events

Iteration and events: the questions

Quiz Challenge, round 1: Quiz Blitz

  1. What does iteration mean?

    • Starting a script
    • Repeating instructions
    • Choosing between two paths
    • Storing a value
  2. How many sides does this draw?

    repeat 4
        move 100 steps
        turn right 90 degrees
    • 1
    • 90
    • 100
    • 4
  3. Which loop runs until the program is stopped?

    • when green flag clicked
    • forever
    • repeat 10
    • repeat until
  4. Which loop keeps going until a condition becomes true?

    • repeat 10
    • forever
    • if ... else
    • repeat until
  5. What shape does this draw?

    repeat 3
        move 100 steps
        turn right 120 degrees
    • A triangle
    • A square
    • A pentagon
    • A straight line
  6. To change the square loop into a pentagon, which numbers change?

    • repeat 5 and turn 72 degrees
    • repeat 4 and turn 90 degrees
    • repeat 5 and turn 90 degrees
    • repeat 6 and turn 60 degrees
  7. Writing the same blocks out four times works, but a loop is shorter and easier to change.

    • True
    • False
  8. Which of these blocks is an event?

    • when space key pressed
    • repeat 10
    • move 10 steps
    • change score by 1
  9. What does broadcasting let sprites do?

    • Store a score
    • Draw a square
    • Tell other sprites to do something
    • Repeat forever
  10. Put the debugging checks in the order the lesson gives them.

    Number these 1 to 4.

    • Check each condition is the right way round
    • Check the script is on the right sprite
    • Check the order of the blocks
    • Check every variable is set at the start
  11. Which TWO blocks are events?

    Tick 2.

    • forever
    • repeat 10
    • if touching edge?
    • when green flag clicked
    • when this sprite clicked
  12. How many times does the sprite say Hi?

    repeat 3
        repeat 2
            say "Hi" for 1 seconds

Quiz Challenge, round 2: Quick Fire

  1. Explain the difference between repeat 10 and forever. [2 marks]

  2. Why is a loop better than writing the same blocks out four times? [2 marks]

  3. What is an event? Give an example. [2 marks]

  4. Explain how broadcasting helps sprites work together. [2 marks]

Quiz Challenge, round 3: Big Think

  1. Explain how to draw a regular pentagon in Scratch using a loop. [4 marks]

  2. A Scratch game is not working. Describe how you would debug it. [6 marks]

This or That: tick the right answer

  1. Which loop would draw a square?

    • repeat 4
    • repeat 3
  2. What does a forever loop do?

    • Runs exactly 10 times
    • Runs until the program is stopped
  3. Which block starts a script when you press the space bar?

    • repeat until space
    • when space key pressed
  4. To draw a hexagon, what should each turn be?

    • 60 degrees
    • 90 degrees
  5. repeat until <score = 10> stops when what happens?

    • It has run 10 times
    • The score reaches 10
  6. Which helps sprites work together?

    • Broadcasting a message
    • Using more forever loops
  7. How many times is Hi said?

    repeat 2
        repeat 4
            say "Hi" for 1 seconds
    • 8
    • 6
  8. Your sprite does nothing when the flag is clicked. What should you check first?

    • The script starts with when green flag clicked
    • The colour of the sprite

Memory Match: match each term to its meaning

TermMeaning
A repeat 101 Runs until the program is stopped
B forever2 Starts a script at the start of a game
C repeat until3 Runs exactly 10 times
D when green flag clicked4 Runs until a condition becomes true
E Broadcast5 Repeating instructions
F Iteration6 Sends a message to other sprites
Answers

Round 1: Quiz Blitz

  1. Repeating instructions Iteration means repeating. Scratch has repeat, forever and repeat until.
  2. 4 The loop runs 4 times and draws one side each time: a square.
  3. forever forever never ends by itself.
  4. repeat until repeat until stops as soon as its condition is true.
  5. A triangle Three sides with 120 degree turns make a triangle: 3 x 120 = 360.
  6. repeat 5 and turn 72 degrees Five sides, and 360 / 5 = 72 degrees for each turn.
  7. True Loops make code shorter, clearer and easier to change.
  8. when space key pressed An event starts a script when something happens.
  9. Tell other sprites to do something One sprite broadcasts a message, and other sprites react with when I receive.
  10. Check the order of the blocks → Check every variable is set at the start → Check each condition is the right way round → Check the script is on the right sprite Order, variables, conditions, then the right sprite. Then click blocks one at a time to see what each does.
  11. when green flag clicked; when this sprite clicked Events start scripts. forever and repeat are loops, and if is selection.
  12. 6 The inner loop runs 2 times for each of the 3 outer loops: 3 x 2 = 6.

Round 2: Quick Fire

    • repeat 10 runs a fixed number of times, then stops
    • forever keeps going until the program is stopped
    Model answer

    repeat 10 runs exactly ten times and then stops. forever keeps going until the program is stopped.

    • It is shorter, with less code
    • It is clearer and easier to change
    Model answer

    A loop is shorter and clearer, and it is easier to change: changing one number turns a square into a pentagon.

    • Something happening that starts a script
    • An example such as the green flag being clicked
    Model answer

    An event is something that happens which starts a script, for example when the green flag is clicked.

    • One sprite sends a message
    • Other sprites receive it and react
    Model answer

    One sprite sends a message, and other sprites with a when I receive block react to it, so one sprite can tell another what to do.

Round 3: Big Think

    • Use repeat 5, because a pentagon has five sides
    • Move a number of steps for each side
    • Turn 72 degrees each time
    • Because the turns add up to 360 degrees, and 360 divided by 5 is 72
    • Put the pen down, and note that the loop is shorter than writing it out
    Model answer

    Put the pen down, then use repeat 5, because a pentagon has five sides. Inside the loop, move 100 steps and turn right 72 degrees. The turn is 72 because the turns must add up to 360 degrees, and 360 divided by 5 is 72. The loop is much shorter than writing the blocks out five times.

    • Check the order of the blocks
    • Check every variable is set at the start
    • Check each condition is the right way round
    • Check each script is on the right sprite
    • Click blocks one at a time to see what each does
    • Test again after each change
    • Check the scripts start with the right event
    Model answer

    First I would check the order of the blocks, because the right blocks in the wrong order do the wrong thing. Then I would check every variable is set at the start, when the green flag is clicked. I would check each condition is the right way round, for example > where I meant <. I would make sure each script is attached to the right sprite. Finally I would click blocks individually to see what each one does, and test again after every change.

This or That

  1. repeat 4 A square has four sides, so the loop runs 4 times.
  2. Runs until the program is stopped forever never stops on its own.
  3. when space key pressed An event block starts a script when something happens.
  4. 60 degrees The turns add up to 360 degrees, and 360 / 6 = 60.
  5. The score reaches 10 repeat until stops as soon as its condition becomes true.
  6. Broadcasting a message Broadcast sends a message that other sprites receive and react to.
  7. 8 4 times for each of the 2 outer repeats: 2 x 4 = 8.
  8. The script starts with when green flag clicked Without an event block at the top, the script never starts.

Memory Match

  • A 3 repeat 10: Runs exactly 10 times
  • B 1 forever: Runs until the program is stopped
  • C 4 repeat until: Runs until a condition becomes true
  • D 2 when green flag clicked: Starts a script at the start of a game
  • E 6 Broadcast: Sends a message to other sprites
  • F 5 Iteration: Repeating instructions