Bugs and Debugging
Every coder makes mistakes. Learn what bugs are, the three most common kinds, and how to hunt them down and fix them step by step.
Welcome back!
Step 1 of 12Learn
What is a bug?
A bug is a mistake in an algorithm that makes it do the wrong thing.
In 1947, people working on an early computer found a real moth stuck inside it, making it fail. They taped the moth in their notebook and joked that they had found a "bug." The word stuck around.
Finding and fixing mistakes is called debugging. Every programmer in the world does it, every single day. Making bugs is normal. Fixing them is the skill.
Step 2 of 12Practice · True or false
Good programmers never make bugs.
Step 3 of 12Timeline
A short history of bugs and algorithms
- About 820Al-Khwarizmi
A scholar in Baghdad writes step-by-step ways to solve math problems.
- 1843Ada Lovelace
She writes an algorithm for a machine that was never finished. Many call it the first computer program.
- 1947The moth
A real moth is found inside a computer and taped into a notebook as the first "bug".
- TodayDebugging tools
Programmers use special tools that run code one step at a time.
Step 4 of 12Tap to reveal
Three common kinds of bugs
Wrong order
All the steps are there, but two are swapped. Like pouring milk before you get out the bowl.
Missing step
A step was forgotten. Like a cake recipe that never says to turn on the oven.
Wrong step
A step says the wrong thing. Like "turn left" when you needed to turn right.
Step 5 of 12Learn
How to hunt a bug
Debugging is like being a detective. Here is a plan that works:
- Run the steps and watch what happens.
- Find the first step where things go wrong.
- Fix that one step.
- Test again to make sure it works now.
Try not to change many things at once. Change one thing, then test. That way you know which change fixed it.
Step 6 of 12Practice · Put in order
Put the debugging steps in order.
Drag the items, or use the arrow buttons, to put them in order.
- Test again
- Fix that step
- Find where it goes wrong
- Run the steps and watch
Step 7 of 12Diagram
The bug hunt loop
Tap a shape with to see more.
- Run
Do the steps and watch.
- Find
Spot the first step that goes wrong.
- Fix
Change just that one step.
- Test
Run again. Still wrong? Go around once more.
Step 8 of 12Practice · What would you do?
What would you do?
Mia's cake recipe says: mix flour, sugar and eggs; pour into a pan; take the cake out after 30 minutes. Her cake comes out as cold, gooey batter. What kind of bug is it?
Step 9 of 12Practice · Spot the mistake
Leo wants his robot to walk 2 squares forward, turn right, then walk 1 square to reach the star. The star is to the right. Tap the buggy step.
Step 10 of 12Note
Step 11 of 12Practice · Match the pairs
Match each bug to its kind.
Tap an answer, then tap the place where it belongs (or drag it there).
- Recipe never says "turn on the oven"
- Shoes go on before socks
- "Add 20 cups of salt" instead of 2
Step 12 of 12Practice · Fill in the blanks
Fill in the blanks
Finding and fixing mistakes in an algorithm is called .
Lesson complete!