Learn Without Walls
← Module 6 Home Lesson 4 of 4 Practice Activities →

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:

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
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.

The bug: There is no when green flag clicked block on top. Without it, Scratch does not know when to start. Add it to the top of the stack and the cat will move!
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:

when green flag clicked
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.

The bug: The turn angle is 80 degrees instead of 90. A square needs 90-degree turns (because 90 x 4 = 360, a full rotation). Change 80 to 90 and the square will close perfectly.

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:

when green flag clicked
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.

The bug: The hide block makes the cat invisible before anything else happens. Either remove the hide block entirely, or change it to show. The cat needs to be visible to say hello and walk!

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:

when green flag clicked
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.

The bug: The wait block says 100 seconds. That is almost two minutes! Change 100 to 1 (for a 1-second pause) and the cat will say "Go!" right away. Always check your numbers -- wrong numbers are one of the most common bugs.

Your Debugging Toolkit

Now you have a complete toolkit for debugging Scratch projects:

Scratch Debugging Checklist

  1. Does the code start with when green flag clicked (or another event block)?
  2. Are all the blocks snapped together with no gaps?
  3. Are the numbers correct (not too big, not too small)?
  4. Is the correct sprite selected?
  5. Is the sprite visible (not hidden) and on the stage (not off screen)?
  6. Are the blocks in the right order?
  7. 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?

Answer: The most common reason is a missing "when green flag clicked" block at the top of the stack. Without an event block, Scratch does not know when to start running the code.

2. Your sprite draws an open shape instead of a closed one. What should you check?

Answer: Check the turn angle and the repeat number. For a closed shape, the turn angle multiplied by the repeat number should equal 360. If it does not, the shape will not close properly.

3. Your sprite disappears when you run the code. What are two things to check?

Answer: (1) Check if there is a "hide" block making the sprite invisible. Replace it with "show" or remove it. (2) Check if the sprite moved off the edge of the stage. Add a "go to x: 0 y: 0" block at the start to bring it back to the center.

Key Takeaways

You Finished All the Lessons!

Practice Activities

More debugging challenges to sharpen your detective skills. Can you find all the bugs?

Practice Activities

Module Quiz

Ready to prove your debugging knowledge? Take the Module 6 quiz!

Take the Quiz