Lesson 7 of 10

Debug It! 🐛

🎯 Grades 3–5 ⏱ ~25 minutes 🟠 Intermediate

What You'll Learn

  • What a bug is and where the word comes from
  • How to read a broken program and find the mistake
  • How to fix bugs by testing and comparing results

What Is a Bug?

A bug is a mistake in a program that makes it do the wrong thing. Every programmer — from beginners to professionals — writes bugs. What separates good programmers is how well they find and fix them.

The process of finding and fixing bugs is called debugging.

Where Did "Bug" Come From?

In 1947, a computer at Harvard University stopped working. Engineers found a real moth stuck inside the machine causing the error. They taped it into their logbook and wrote "First actual case of bug being found." The word has meant a software error ever since!

How to Debug

When your program does not do what you expected, follow these steps:

  1. Observe — Run the buggy program. Watch carefully what the turtle actually does.
  2. Compare — Compare what you see to what you wanted. Where did it go wrong?
  3. Hypothesize — Make a guess about which block caused the mistake.
  4. Fix and test — Change that block and run it again. Did that fix it?
  5. Repeat — If it is still broken, repeat the process.
💡
Read Your Program Like a Story

Go through each block one at a time in your head and picture what the turtle is doing at that exact moment. The bug is usually in the block where your mental picture diverges from what you wanted.

Three Buggy Programs to Fix

Below are three programs that are supposed to draw a square — but each one has a different bug. Load each one, run it to see what it draws, find the bug, and fix it.

Bug 1 — Wrong step count: The program uses 4 moves and 4 turns but the sides are unequal. Find which Move block has the wrong number and fix it.

Expected: Move Forward 80 → Turn Right 90° → repeated 4 times

Bug 2 — Wrong turn direction: The program moves and turns but the turtle spirals instead of making a square. One turn block is pointing the wrong way.

Bug 3 — Missing block: The program draws 3 sides of a square and stops. Something is missing at the end.

Quick Check

1. What is a bug in programming?

AA type of turtle command
BA mistake in a program that causes wrong behavior
CA feature that only expert coders use

2. What is the first step in debugging a program?

ADelete everything and start over
BObserve what the program actually does
CAsk someone else to fix it

3. The word "bug" in programming comes from…

AA cartoon character
BA real moth found inside a 1947 computer
CA type of computer chip