GoalTurn each line of an algorithm into one Scratch block.
New words
algorithm · a list of steps that solves a problem or does a jobhat block · a block that starts a script when something happensscript · a stack of blocks that a sprite follows
Explanation
A good way to make a program is to write the algorithm first, as a table of steps. Then you change each line into one block. The line that says what starts the program becomes a hat block from the Events group. A line about moving becomes a Motion block. A line about saying or changing costume becomes a Looks block. A line about waiting becomes a Control block. Snap the blocks together in the same order as the lines. At the end, check each block against its line.
Worked examples
Step
Instruction
1
When the green flag is clicked
2
Go to x: −150, y: −60
3
Say “Time to rest!” for 2 seconds
4
Glide for 3 seconds to x: 100, y: −60
5
Switch to the next costume
A hen has to walk to a nest and sit down. Here is the algorithm for the hen. The nest is a static object and has no code.
Here is the stage. The hen starts on the left and glides to the nest on the right. The nest stays where it is.
Line
Block
Group
1
when ⚑ clicked
Events
2
go to x: −150 y: −60
Motion
3
say Time to rest! for 2 seconds
Looks
4
glide 3 secs to x: 100 y: −60
Motion
5
next costume
Looks
Each line becomes one block, and each block comes from a group.
Class activity
Block cards (with a friend): write the lines of an algorithm for a fish on separate cards: “When the green flag is clicked”, “Go to x: −100, y: 0”, “Wait 1 second”, “Say Bubbles! for 2 seconds”, “Glide for 2 seconds to x: 100, y: 0”. Next to each one, write the Scratch block it becomes and its group. Lay the second row of cards under the first. Does every line have a block? If you have a computer or tablet, build the program in Scratch and click the flag.
Practice
1
Write the block for each step. (a) Wait 2 seconds. (b) Say “Good morning!” for 3 seconds. (c) Go to x: 0, y: 50. (d) Switch to the next costume.
(a) wait (2) seconds (b) say [Good morning!] for (3) seconds (c) go to x: (0) y: (50) (d) next costume
2
Write the algorithm as a table of steps for this program.
1 When the green flag is clicked. 2 Go to x: −100, y: 0. 3 Say “Hello!” for 2 seconds. 4 Wait 1 second. 5 Glide for 2 seconds to x: 100, y: 0.
3
The algorithm says: 1 When the green flag is clicked. 2 Go to x: −80, y: 20. 3 Wait 1 second. 4 Glide for 2 seconds to x: 120, y: 20. One block is wrong. Which one, and how do you fix it?
The glide block. It says 1 second, but the algorithm says 2 seconds. Change it to glide (2) secs to x: (120) y: (20).
4
Which group of blocks do these come from? wait (1) seconds · say [Hi!] for (2) seconds · when green flag clicked · glide (2) secs to x: (0) y: (0)
wait: Control. say: Looks. when green flag clicked: Events. glide: Motion.