Skip to content

Chapter 2 - Debugging Like a Computer Scientists

Sometimes, even computers make mistakes—but not on purpose! When something goes wrong in a computer program, it’s usually because there’s a bug. A bug is a little error in the instructions we gave the computer. But don’t worry! When we find and fix bugs, we’re doing something very important called debugging.

Let’s say that word together: de-bug-ging.
Debugging means: finding and fixing mistakes in a computer program.

2.1 Bugs Happen—And That’s Okay!

We all make mistakes, even when we’re trying our best. Have you ever:

  • Put your shoes on the wrong feet?
  • Spelled a word the wrong way?
  • Added numbers and got the wrong answer?

Those are bugs too! And just like in computer science, we can fix them by figuring out what went wrong and trying again.

We played a game in class where the teacher was a robot, and we had to tell the robot how to reach Glitch. But what if our instructions were wrong?

For example:
walk, walk, turn left, walk — Uh oh! That didn’t get the robot to Glitch.

We had to debug the instructions—look closely, figure out what didn’t work, and change it.

2.2 Debugging in Games

When we use the codeSpark Academy App, we help a character named Gracie find delicious donuts by giving her commands. But sometimes she doesn’t get to the donut like we planned. That’s a sign we have a bug in our code.

That’s okay! We use something called the Test and Learn steps to debug:

  • Understand the problem: What is going wrong?
  • Plan: What should we change in our instructions?
  • Test it: Try the new commands.
  • Learn: Did it work? If not, let’s try again.

Let’s say Gracie was supposed to jump over boxes but instead she just walked into them. That’s a bug! So we change the code to add “jump” commands. That’s debugging!

Computer scientists try, test, and try again. They never give up—and neither should you!

2.3 Bugs in Real Life

Sometimes bugs don’t just happen on computers—they happen in our everyday lives too!

Here are some real-life bugs:

  • You poured cereal before getting a bowl.
  • You tried to zip your jacket before putting it on.
  • You said, “My dog ran house,” instead of “My dog ran to the house.”

When you notice something’s wrong and fix it, you’re debugging!

Let’s draw or write a story about a time you had to debug something in your life. Maybe you spilled water and had to clean it up. Maybe you built a tower with blocks and it fell down, so you tried again. That’s what computer scientists do too!

2.4 Learning from Grace Hopper

Did you know the first computer bug was a real bug? A moth flew into a big computer called the Mark II a long time ago. A computer scientist named Grace Hopper found it and said, “We need to debug the machine!” That’s where the word came from!

Grace Hopper was one of the first people to work with computers. She showed that anyone—even someone who isn’t a robot—can be a great computer scientist.

2.5 Let’s Reflect

  • What is a bug in coding?
  • What does debugging mean?
  • Have you ever debugged something in your own life?
  • Why is it important to try again when something doesn’t work the first time?

Remember: making mistakes is how we learn. Debugging helps us get better every time. You are already thinking like a real computer scientist!

TermDefinition
BugA mistake or error in a computer program that causes it to not work correctly.
DebuggingThe process of finding and fixing bugs in a computer program.
ErrorSomething that goes wrong or is incorrect, like a bug in code or a mistake in math.
TestTrying out a program to see if it works the way you want it to.
LearnLooking at what happened after testing to understand what went wrong or right.
FixTo correct a mistake or problem so everything works properly.
Grace HopperOne of the first computer scientists who helped create the idea of debugging.
PersistenceTrying again and not giving up when something doesn’t work the first time.