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

Debug together

Week 15 · Unit 6: Be a designer · 3 lessons
1

Find the bug

Computing 2: Unit 6, pp. 80–91
GoalSay what a bug is and find it by comparing a program with its algorithm.
New words
bug · a mistake in an algorithm or a programdebug · to find a bug and fix itcompare · to look at two things to see how they are the same or different
Explanation

A bug is a mistake in an algorithm or a program. To debug means to find the bug and fix it. We find a bug by comparing the program with the algorithm, one step at a time. Look for a wrong block, a wrong number, a missing block or blocks in the wrong order. Fix one bug, then run the program again.

Kind of bugAlgorithm saysProgram has
wrong blockhop 2grow 2
wrong numberright 4right 5
missing blocksay “Hi!”(nothing)
wrong orderup 1, then left 2left 2, then up 1
Worked examples
3Go!
The algorithm says: start on tap, say “Go!”, right 3, pop, end. Compare each block. Steps 2 and 3 are in the wrong order. The character moves before it speaks.
The algorithm says: right 4, then up 2, to reach the star. The program says right 4, then up 3. The cat goes one square too far.
2
The algorithm says: start on tap, say “Hi!”, hop 2, end. The program has no say block. The say block is missing.
Class activity

Bug hunt (with a partner): one of you writes an algorithm with five steps on paper, for example “start on flag, right 2, hop 1, say Go!, end”. Then draw five block cards for a program, but make one mistake on purpose. Hide the mistake. Your partner puts the cards next to the algorithm and checks them one by one with a finger. Can they find the bug? Swap roles.

Practice
1
The algorithm says: start on green flag, left 2, grow 1, play pop, end. Find the bug in the program.
21start ongreen flagmoveleftshrinkpopend
2
What does it mean to debug a program?
3
The cat should go right 3 and then down 2 to the fish. The program says right 3, up 2. The line shows where the cat went. Which block is the bug and what must it be?
4
Name two kinds of bug.