AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Fixing mistakes

Week 9 · Unit 4: Be an animator · 3 lessons
2

Check the path

Computing 2: Unit 4, pp. 54–65
GoalCheck an algorithm against a path, find the bug and fix it.
New words
check · to look carefully to see if something is rightdirection · the way something moves, such as up, down, left or rightfix · to change something so that it is right
Explanation

A path shows where a character must go. We write an algorithm for it. Then we check the algorithm against the path, step by step. We count the squares for each step. If a number or a direction does not match the path, we have found a bug. We change that step and check again. In the picture the path goes right 3, down 2 and right 2.

Worked examples
324
The path above is right 3, down 2, right 2. This program has a bug in its last move block. The path needs right 2, but the block says right 4.
23
This program has a bug in its direction. The path should go up 2 and then right 3, but the first move block points down.
A bug can also be a missing step. If the path has three straight parts and the program has only two move blocks, a step is missing.
Class activity

Treasure map (two players): draw a grid of 6 squares across and 5 down. Hide a treasure by drawing a star in one square. Mark a start. Write an algorithm of three move steps that goes from the start to the star, but change one number so it has a bug. Give it to your friend. They move a coin along the steps, find where it goes wrong and fix the step.

Practice
1
The algorithm says: up 2, right 5. Does it match the path? What is the bug?
2
The path should go right 4 and then up 2. The red block has a bug. What number must it have?
43
3
The path goes down 3 and then left 2. The algorithm says: down 3, right 2. What is the bug?
4
Why do we check each step against the path?