Computer Science
Grade 3
20 min
Debugging Common Errors: Fixing Mistakes
Students will learn how to fix common errors such as syntax errors, logic errors, and runtime errors.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define the terms 'bug' and 'debugging' using their own words.
Identify a bug in a simple sequence of code blocks.
Explain what a program was expected to do versus what it actually did.
Correct a mistake in a conditional (if/then) statement.
Fix a bug related to a wrong event trigger.
Use a step-by-step process to find and fix one error in a program.
Have you ever tried to follow a recipe, but missed a step and your cookies came out funny? 🍪 Our computer programs can have 'funny cookies' too, and we're going to become detectives to fix them!
Today, we're putting on our detective hats to learn about 'bugs,' which are little mistakes in our code. We will learn how to find these bugs and fix them, a skill ca...
2
Key Concepts & Vocabulary
TermDefinitionExample
BugA mistake or error in your code that makes the program do something you didn't want it to do.You tell your character to jump when you press the spacebar, but instead it spins around. The spinning is a bug!
DebuggingThe process of finding and fixing bugs in your code. It's like being a code detective!You look at your code blocks and find you accidentally used a 'spin' block instead of a 'jump' block. Changing it is debugging.
SequenceThe order that instructions happen in your code. Computers follow the steps one after another.1. Move forward. 2. Turn right. 3. Say 'Hello!'. If the order is wrong, the program won't work as expected.
EventAn action that makes a piece of code start. It's the 'When...' part of...
3
Core Syntax & Patterns
Detective Rule #1: Test and Observe
Run your code and watch it carefully.
First, see what the program actually does. Compare what you see happening with what you wanted to happen. The difference is your first clue!
Detective Rule #2: Check One Block at a Time
Read your code in order, from top to bottom.
Just like reading a book, read your code blocks one by one. Ask yourself, 'Is this block doing what I think it should be doing?' This helps you find the exact spot where the mistake is.
Detective Rule #3: Test Small Changes
Change only one thing, then test your code again.
When you think you've found the bug, fix just that one thing. Then run the program to see if your fix worked. If you change too many things at once, you won't know which change w...
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
A sprite moves back and forth using `FOREVER { MOVE 10 steps; IF on edge, bounce }`. After it bounces, it is always upside down. What block can you add to fix this?
A.`set rotation style left-right` block
B.`turn 180 degrees` block
C.`go to x:0 y:0` block
D.`change size by 10` block
Challenging
You have a list of friends: `[Ali, Ben, Chloe]`. To say the last friend's name, you use `SAY item 3 of friends`. If you add "David" to the list, how can you change the code to ALWAYS say the last name, no matter how long the list is?
A.Change the code to `SAY item 4 of friends`
B.Use a block like `SAY item (length of friends) of friends`
C.Put David's name at the beginning of the list
D.Create a new list for every new friend
Challenging
A game has 3 levels. Each time you finish a level, the code `SET level to 1` runs. You finish level 1, and the game says you are on level 1. You finish level 2, but the game still says you are on level 1. What is the bug?
A.The game can only have one level
B.The variable name should be `score` not `level`
C.The code should `CHANGE level by 1`, not `SET level to 1`
D.The computer is stuck on level 1
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free