Lesson 4: Debugging in Scratch
Estimated time: 15-20 minutes | Scratch Activity
What You Will Learn
By the end of this lesson, your child will be able to:
- Recognize the 5 most common bugs in Scratch projects
- Use the debugging detective steps to fix broken Scratch code
- Fix at least 3 intentionally broken Scratch programs
The 5 Most Common Scratch Bugs
After working with many young coders, we have found that most Scratch problems come from the same five mistakes. Once you know what they are, you can spot them quickly!
Bug 1: Missing "When Green Flag Clicked"
You built a great stack of blocks, but nothing happens when you click the green flag. The most common reason? Your stack of blocks does not start with when green flag clicked. Without this block on top, Scratch does not know when to run your code.
Fix: Add the event block on top
Go to the Events category (yellow blocks) and drag when green flag clicked to the top of your stack. Now click the green flag and your code will run.
Bug 2: Blocks Not Connected
Your blocks look right, but some of them are floating separately on the screen instead of snapped together. Scratch only runs blocks that are connected in a stack. If there is a gap, Scratch stops at the gap.
Fix: Snap all blocks together
Drag the loose blocks and snap them onto the bottom of the stack. You will see them click into place. Make sure there are no gaps anywhere in your stack.
Bug 3: Wrong Numbers
Your sprite moves too far, turns the wrong amount, or waits too long. The blocks are in the right order, but the numbers inside them are wrong. For example, move (1000) steps will send the cat flying off the screen!
Fix: Check and change the numbers
Click on the number inside any block to change it. Try smaller numbers first. For movement, 10-100 steps is usually good. For turns, common angles are 90 (quarter turn), 120, and 360 (full spin).
Bug 4: Wrong Sprite Selected
You are adding blocks, but they are going to the wrong sprite! If you have more than one sprite, you need to make sure the right one is selected (highlighted in blue) before you add blocks to it.
Fix: Click the correct sprite first
Look at the sprite list below the stage. Click on the sprite you want to give blocks to. It will have a blue border when selected. Now any blocks you add will belong to that sprite.
Bug 5: Sprite Is Hidden or Off Screen
Your code runs, but you cannot see anything happening. The sprite might be invisible (someone used a hide block) or it might have moved off the edge of the stage.
Fix: Show the sprite and reset its position
Add show and go to x: (0) y: (0) at the start of your code to make sure the sprite is visible and centered.
Talk About It (Parent and Child)
Ask your child: "Which of these 5 bugs do you think is the most common?" (Bug 1 -- missing the green flag block -- happens most often!) "Have you ever had one of these problems before?" Connecting to their own experience helps the lesson stick.
Debug Challenge 1: The Cat That Will Not Move
Scratch Activity: Find the Bug
The goal: When you click the green flag, the cat should walk across the screen.
The broken code:
move (10) steps
move (10) steps
move (10) steps
move (10) steps
What happens: You click the green flag and... nothing.
Your job: Build this code in Scratch and fix it so the cat walks when you click the green flag.
Bonus fix: You could also replace the 5 separate move blocks with a loop: repeat (5) with move (10) steps inside.
Debug Challenge 2: The Wonky Square
Scratch Activity: Find the Bug
The goal: Draw a square using a loop.
The broken code:
erase all
pen down
repeat (4)
move (100) steps
turn right (80) degrees
What happens: The shape does not close. It looks weird and is not a square.
Your job: Build this code and find the bug.
Debug Challenge 3: The Invisible Cat
Scratch Activity: Find the Bug
The goal: The cat should say "Hello!" and walk to the right.
The broken code:
hide
say "Hello!" for (2) seconds
move (50) steps
What happens: You click the green flag and the cat disappears. You cannot see it saying "Hello!" or moving.
Your job: Build this code and fix it.
Debug Challenge 4: The Endless Wait
Scratch Activity: Find the Bug
The goal: The cat should say "Ready," wait 1 second, then say "Go!" and run forward.
The broken code:
say "Ready!" for (2) seconds
wait (100) seconds
say "Go!" for (2) seconds
repeat (10)
move (20) steps
What happens: The cat says "Ready!" but then nothing happens for a very long time.
Your job: Build this code and figure out why it takes so long.
Your Debugging Toolkit
Now you have a complete toolkit for debugging Scratch projects:
Scratch Debugging Checklist
- Does the code start with when green flag clicked (or another event block)?
- Are all the blocks snapped together with no gaps?
- Are the numbers correct (not too big, not too small)?
- Is the correct sprite selected?
- Is the sprite visible (not hidden) and on the stage (not off screen)?
- Are the blocks in the right order?
- If using a loop, is the repeat number correct?
Go through this checklist every time something is not working. Most bugs will be caught by one of these checks!
Scratch Activity: Break and Fix
Here is a fun way to practice: build a simple project that works, then intentionally break it by changing one thing. Have your parent or sibling try to find and fix the bug you created! Then switch roles and have them break a project for you to debug.
Making bugs on purpose is a great way to understand how they work.
Check Your Understanding
1. What is the most common reason code does not run when you click the green flag?
2. Your sprite draws an open shape instead of a closed one. What should you check?
3. Your sprite disappears when you run the code. What are two things to check?
Key Takeaways
- The 5 most common Scratch bugs are: missing event block, disconnected blocks, wrong numbers, wrong sprite selected, and hidden/off-screen sprite
- Use the Scratch Debugging Checklist to systematically check for problems
- Always check numbers carefully -- wrong numbers are one of the sneakiest bugs
- Breaking code on purpose is a great way to learn how bugs work
- The debugging skills you learned in this whole module work for Scratch, everyday life, and all future coding
You Finished All the Lessons!
Practice Activities
More debugging challenges to sharpen your detective skills. Can you find all the bugs?
Practice Activities