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.
To debug, we check our steps one by one. We look for the exact spot where things go wrong, then we fix it.
✏️ 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!
- Read the goal: The robot needs to go to the right to reach the star.
- Check Step 1: The robot steps forward. This is correct because it gets closer to the path.
- 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!
- Remove the error: Change 'Turn Left' to 'Turn Right'.
- Check Step 3: The robot steps forward. Now that it turned right, stepping forward leads it straight to the star!
- 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?