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

Build, test and reset

Week 15 · Unit 6: Be an animator · 3 lessons
1

Build it, test it, fix it

Computing 5: Unit 6, pp. 70–85
GoalBuild a script with an if block from a plan, test it against a prediction and find common bugs.
New words
build · to put blocks together to make a scripttest · to run a program and compare what it does with what we predictedbug · a mistake in an algorithm or a programdebug · to find a bug and fix it
Explanation

To build a script, first select the right sprite. Add the hat block that matches the input, and the blocks of the action under it. Then add an if block, put the condition in its pointed slot and put the conclusion blocks inside it. Next, test the program. Predict the result first, run it and compare. If the two are different, there is a bug. Look for the wrong sprite, a wrong number, a wrong dropdown choice or blocks in the wrong place.

Worked examples
whenspacekey pressedmove15stepsiftouchingLamp?thensayWarm!for2seconds
Bug 1: the say block is under the if block and not inside it. It is no longer part of the conclusion, so the Moth says ‘Warm!’ after every key press, even when it is not touching the Lamp.
whenclickedsayDinner!for2secondsiftouchingFish?thenmove5stepsforever
Bug 2: the if block is outside the forever block. The condition is checked once, right at the start, before the Heron has moved. The Heron never says ‘Dinner!’ when it reaches the Fish.
TestExpectedActualMatch?
flag, no key pressedMoth stays stillMoth stays stillyes
space pressed once, far from the Lampno speechsays Warm!no
space pressed 4 times, touching the Lampsays Warm!says Warm!yes
A test table helps. Each row has an expected result, worked out first, and an actual result, seen when the program runs. A row that does not match shows a bug.
Class activity

Human computer (3 players). The programmer writes a short algorithm on a card, with one if step, for example ‘Start when a button is tapped. Move the counter 2 squares. If the counter is on the star, then clap.’ The computer follows each step exactly, one at a time, moving a counter on a drawn track. The tester writes the expected result before the computer starts, and compares it with the actual result. Then the programmer secretly swaps two steps on the card to make a bug. Can the tester find which step is wrong?

Practice
1
A sprite touches the Fish but never says ‘Dinner!’. Give three places to look for the bug.
2
The Kite should say ‘Wheee!’ when it touches the Cloud, but it never does. Find the bug and fix it.
whenup arrowkey pressedchange y by10sayWheee!for1secondsiftouchingSun?then
3
The Beetle starts at x: -75 and moves 25 steps for each key press. The Log is at x: 0 (they touch only on the same spot). Complete the test table. On which press does the Beetle say ‘Found it!’?
Press1234
Beetle’s x????
Says Found it!?????
4
Kai wants the Cat to meow when the space key is pressed. His script starts with ‘when this sprite clicked’. What goes wrong, and how can he fix it?
when this sprite clickedstart soundMeowifkeyspacepressed?then