Computer Science
Grade 2
20 min
The Broken Toy
Identifying what's wrong with a broken toy and suggesting a fix.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define the word 'bug' as a mistake in code.
Define 'debugging' as finding and fixing bugs.
Identify a bug in a simple sequence of code blocks.
Identify a bug in a simple loop.
Explain the steps to fix a simple bug.
Test their code after fixing a bug to see if it works.
Oh no! Your toy robot is supposed to dance, but it just wiggles its arm. 🤖 What's wrong?
We will learn how to be code detectives! We will find clues, called 'bugs', in our code. Then we will learn how to fix them, which is called 'debugging'.
Real-World Applications
Fixing a video game that freezes 🎮
Helping a toy robot follow the right path ➡️
Making sure a cartoon character moves correctly 🐰
Figuring out why a puzzle piece doesn&#...
2
Key Concepts & Vocabulary
TermDefinitionExample
Bug 🐞A bug is a mistake or an error in the code. It makes the program do something wrong.You want your cat character to say 'Meow', but it says 'Woof' instead. The 'Woof' is a bug.
Debugging 🕵️Debugging is the process of finding and fixing bugs. You are a bug detective!You find the 'Woof' code block and change it to a 'Meow' block. You are debugging!
Code 🧱Code is a set of instructions you give to a computer. We use code blocks.The blocks [Move Forward] -> [Turn Left] are code that tells a character what to do.
Sequence ➡️A sequence is the order that instructions happen. Step 1, then Step 2, then Step 3.To make a sandwich, you FIRST get bread, THEN add jelly. The order matters!
Loop 🔄A loop is an instruction tha...
3
Core Syntax & Patterns
Rule 1: One Step at a Time
Look at each code block one by one, from top to bottom.
Use this to carefully check your code. Don't skip any blocks! This helps you find exactly where the bug is hiding.
Rule 2: Compare and Check
Ask: 'What SHOULD it do?' 🤔 Then ask: 'What IS it doing?' 😮
Use this when you see a problem. First, think about your goal. Then, watch what the program does. The difference is the bug!
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 toy car needs to drive around a box, making a square path. The code is: [Move Forward], [Turn Right]. What must be added to this code to make it work?
A.Nothing, it's correct.
B.One more [Move Forward] block.
C.Put the blocks in a 'Repeat 4 times' loop.
D.An [End] block.
Challenging
A dancing robot should spin, then clap, then jump. The code is: [Clap], [Jump]. It's missing the spin! Where is the best place to add the [Spin] block?
A.After the [Jump] block.
B.Before the [Clap] block.
C.Between the [Clap] and [Jump] blocks.
D.It doesn't matter where it goes.
Challenging
A toy must stack a red block, then a blue block. The code is [Repeat 2 times: Pick up block, Place block]. Why will this code NOT work for this specific task?
A.The loop repeats too many times.
B.The loop does not say WHICH color block to pick up.
C.The loop repeats too few times.
D.The toy cannot pick up blocks.
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free