Studyfin Studyfin ✨ Sign up free

Debugging

Grade 5 · Coding · Free lesson

Hi there! I am Studyfin, your coding buddy. Today we will learn how to find and fix mistakes in our code!

An algorithm is a list of steps to finish a task. When we write these steps for a computer, we must be very clear.

Sometimes, our steps have a mistake. In coding, a mistake is called a bug! Debugging means finding and removing that error.

Debugging!

To debug, we check our steps one by one. We look for the exact spot where things go wrong, then we fix it.

Step 1: Move Forward (OK) Step 2: Turn Left (ERROR! Should be Right) Step 3: Fixed! Turn Right (SUCCESS)
✏️ Worked example

Help a robot reach a gold star. The star is to the right. The robot has this algorithm, but it has a bug: 1. Step Forward 2. Turn Left 3. Step Forward Let's debug this algorithm together to fix the error!

  1. Read the goal: The robot needs to go to the right to reach the star.
  2. Check Step 1: The robot steps forward. This is correct because it gets closer to the path.
  3. Check Step 2: The robot turns left. Wait! The star is to the right. If the robot turns left, it will go the wrong way. We found the bug!
  4. Remove the error: Change 'Turn Left' to 'Turn Right'.
  5. Check Step 3: The robot steps forward. Now that it turned right, stepping forward leads it straight to the star!
  6. Test the new code: 1. Step Forward, 2. Turn Right, 3. Step Forward. It works perfectly!
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons