3
Spot the mismatch
Computing 2: Unit 10, pp. 134–148
GoalCompare an algorithm with a program and find the blocks that do not match.
New words
match · to be the samemismatch · two things that should be the same but are notdebug · to find and fix errors
Explanation
A program should match its algorithm. Read the algorithm step by step. Read the blocks in the same order. Look at each block and each number. If a block is different from the step, that is an error. Change the block so that it matches. Then test again.
| Step | Instruction |
|---|---|
| 1 | Start on tap |
| 2 | Move up 4 |
| 3 | Hop 2 |
| 4 | Stop |
Worked examples
Here is a program for the algorithm above. The hop block says 3, but the step says 2. The red outline shows the error. Change 3 to 2.
The algorithm is: start on bump, turn right 3, hop 1, stop. This program has two errors. The first block is a tap, and the hop says 2. Fix them one at a time, and test after each fix.
After you fix an error, test again. Sometimes a fix shows another error, or the program is right at last.
Class activity
Mistake detectives (pairs): each of you writes an algorithm of four steps and makes the block cards for it. Secretly change one card so that it does not match, for example a different number. Swap. The detective puts the algorithm next to the cards, checks step by step, finds the mismatch and fixes it.
Practice
1
The algorithm is: start on green flag, move left 2, say “Yes!”, stop. Which block does not match?
The move block. It moves right but should move left 2.
2
The algorithm says hop 3. The block says hop 5. What do you change?
Change the 5 to a 3.
3
The algorithm is: start on tap, move up 1, hop 2, say “Hi!”, stop. Which block is missing?
A hop block with 2.
4
Why should you test again after you fix an error?
To check that the fix works and that there is no other error.