Debugging a visual program

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Debugging a visual program

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Your sprite says 'Goodbye' before it says 'Hello', but you wanted 'Hello' first. What is the bug?
A The sprite is broken and must be deleted
B The blocks are in the wrong order
2. Your program has three scripts and something goes wrong. What is a smart way to find the bug?
A Run one script at a time to see which one causes the problem
B Delete all the scripts and start again
3. Your score variable should go up by 1, but it shows 0 all the time. How can you check what is happening?
A Show the variable on the stage and watch its value
B Guess and change random blocks
4. Your game should say 'You win!' when score = 10, but it says it when score = 1. Which kind of bug is this?
A A wrong condition
B A wrong block order
5. What does debugging mean?
A Making the sprite look nicer with new costumes
B Finding the block that causes a wrong result and fixing it

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Run one script at a time Aif score < 10 then say You win!
2Show variable score BTest a single script on its own so you can tell which script is causing the wrong result
3A wrong block order bug: the sprite should say 'Ready!' after it moves, but it says it before CDisplay the value of the variable on the stage so you can check if it changes the way you expect
4A wrong condition bug: the sprite should only celebrate when the score is more than 10, but it celebrates at 3 DThe blocks are in the wrong order. Set score to 0 should come first so the game starts fresh.
5when green flag clicked, say Go! , set score to 0, move 10 steps (the score never resets before the game starts) Esay Ready! for 2 seconds, then move 50 steps
6repeat until lives = 10 (the game never ends because lives starts at 3 and goes down) FThe condition is wrong. The loop should repeat until lives = 0, so it can actually stop.

Definitions

debugging

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
___ score to 0 change score by 1 say score for 2 seconds
2.
show variable _____ change score by 1 say score for 2 seconds
3.
if score _ 10 then say You win! end
4.
when green flag clicked stop _____ scripts in sprite
5.
repeat until lives = 0 change lives by __ end

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A when green flag clicked
B set score to 0
C repeat 3
D change score by 0
E say score
Question 2
A when green flag clicked
B hide
C say Ready! for 2 seconds
D hide
Question 3
A when green flag clicked
B ask Enter your score
C if answer < 50 then
D say You pass!
Question 4
A when green flag clicked
B set lives to 3
C hide variable lives
D change lives by -1
Question 5
A when left arrow key pressed
B move 10 steps
C say Moving right

Answer Key

Debugging a visual program
Section A: Quick Questions
Q1
B — The blocks are in the wrong order
Q2
A — Run one script at a time to see which one causes the problem
Q3
A — Show the variable on the stage and watch its value
Q4
A — A wrong condition
Q5
B — Finding the block that causes a wrong result and fixing it
Section B: Match the Pairs
Q1
Run one script at a time → Test a single script on its own so you can tell which script is causing the wrong result
Q2
Show variable score → Display the value of the variable on the stage so you can check if it changes the way you expect
Q3
A wrong block order bug: the sprite should say 'Ready!' after it moves, but it says it before → say Ready! for 2 seconds, then move 50 steps
Q4
A wrong condition bug: the sprite should only celebrate when the score is more than 10, but it celebrates at 3 → if score < 10 then say You win!
Q5
when green flag clicked, say Go! , set score to 0, move 10 steps (the score never resets before the game starts) → The blocks are in the wrong order. Set score to 0 should come first so the game starts fresh.
Q6
repeat until lives = 10 (the game never ends because lives starts at 3 and goes down) → The condition is wrong. The loop should repeat until lives = 0, so it can actually stop.
Section C: Definitions
Q1
debugging — Finding the block that causes a wrong result in a program and fixing it, such as a block in the wrong order or a wrong condition.
Section D: Fill in the Blanks
Q1
set score to 0 change score by 1 say score for 2 seconds
Q2
show variable score change score by 1 say score for 2 seconds
Q3
if score > 10 then say You win! end
Q4
when green flag clicked stop other scripts in sprite
Q5
repeat until lives = 0 change lives by -1 end
Section E: Spot the Error
Q1
D — Changing the score by 0 means it never goes up, so the sprite says 0. Showing the score variable helps you spot this. It should be change score by 1.
Q2
B — The blocks are in the wrong order. The sprite is hidden before it speaks, so you cannot see it say anything. Line 2 should be show.
Q3
C — The condition is wrong. A score of 80 would not pass, but a score of 10 would. It should be if answer > 50 then.
Q4
C — Hiding the variable means you cannot watch its value change while you debug. It should be show variable lives.
Q5
A — When you run this script on its own, the right arrow key does nothing. The wrong key is used in the event block. It should be when right arrow key pressed.