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

Counting and asking

Week 10 · Unit 4: Be a storyteller · 3 lessons
3

Fix it and look ahead

Computing 5: Unit 4, pp. 44–57
GoalDebug a program by comparing it with its algorithm, and say what extensions and text-based languages are.
New words
debug · to find a bug and fix itextension · a set of extra blocks that can be added to Scratch, such as Pen or Musicblock-based language · a language where we build programs by snapping blocks togethertext-based language · a language where we type the instructions with words and symbols
Explanation

To debug a program, compare the code with the algorithm, one step at a time. Look for four common bugs: a step in the wrong order, a wrong number, a wrong word or variable name, and a script on the wrong sprite. Then trace the program, change one thing and test again. Scratch can also be extended. An extension adds a new group of blocks. Pen adds drawing blocks. Music adds sound blocks. Text to Speech adds a block that reads words aloud. Scratch is a block-based language. Other languages are text-based, and in them we type instructions. Both kinds use the same ideas: sequences, loops, choices and variables.

BugExampleFix
wrong orderhide comes before showswap the two blocks
wrong numbermove 200 instead of 20change the number
wrong namea different variable is selectedselect the right variable
wrong spritethe script is on another spritedrag it to the right sprite
Worked examples
Code with a bugwhenclickedhidesayWelcome!for2secondsshowFixed codewhenclickedshowsayWelcome!for2secondshide
The algorithm says: show, say ‘Welcome!’ for 2 seconds, hide. The code has hide first and show last. The sprite hides and then talks while hidden, and at the end it shows. Swapping the first and last blocks fixes it.
whenclickedspeakHello!
An extension adds blocks. After the Text to Speech extension is added, a sprite can read a message aloud. Extensions are added with the button in the bottom-left corner of Scratch, and a grown-up should help.
sayHello!for1secondsrepeat3
In a block-based language we drag blocks, like this repeat. In a text-based language the same repeat would be typed as words and symbols. The idea is the same.
Class activity

Bug hunt (pairs). Each player writes an algorithm of four steps for a sprite, for example ‘show, say hello, wait, hide’. Then each player writes a ‘code’ version on paper with exactly one bug: a step in the wrong order, a wrong number or a wrong word. Swap papers. Compare the code with the algorithm, step by step, and find the bug. Say which of the four types of bugs it is. How did you find it?

Practice
1
The algorithm says ‘Move 20 steps’ and the code says ‘move (200) steps’. What type of bug is this? How do you fix it?
move200steps
2
Say what type of bug each is: (a) ‘hide’ is placed before ‘show’, (b) the script is on the wrong sprite, (c) the variable ‘score’ is chosen but ‘points’ was meant.
3
Give two differences between a block-based language and a text-based language.
4
What is an extension in Scratch? Name one and say what it adds.