# Debugging: Finding & Fixing the Bug > Students learn that even great coders make mistakes — called bugs — and that debugging is the fun detective work of finding the one broken step and fixing it. **Computer Science** | **Grades 3–5** *A free lesson plan from K12 Academics. Source page: https://lessonplans.k12academics.com/k12-lesson-debugging.html* Students learn that even great coders make mistakes — called bugs — and that debugging is the fun detective work of finding the one broken step and fixing it. **Copy link** works with Canvas, Schoology, Moodle and any other LMS — paste it in as a resource or assignment. ## Everything you need before the bell rings ### Learning Objectives Students will be able to… - Explain that a **bug** is a mistake in a program. - **Find** the bug in a short program. - **Fix** the bug so the program works. - Explain that debugging is a normal part of coding. Your program doesn’t work — but the computer isn’t “wrong,” it did exactly what you said. So how do you find the one step that’s off? ## Find the Bug Project each buggy program and read it aloud. Have students find the one command that’s wrong — the tool explains how to fix it. ## 45 minutes, five moves Tap any phase to open the teacher moves and student actions. ### Warm-Up — It’s Not Working! A program runs but does the wrong thing — whose “fault” is it? #### 👩‍🏫 Teacher Moves - Show a program that misbehaves. - Explain the computer did exactly what was written. - Set the goal: debugging. #### 🎒 Student Actions - Watch it go wrong. - Realize the steps are off. - Predict what “bug” means. ### Learn — Bugs Are Normal Teacher models debugging. #### 👩‍🏫 Teacher Moves - Define bug and debug. - Model reading a program step by step. - Find and fix one bug aloud. #### 🎒 Student Actions - Learn bug vs. debug. - Follow the step-by-step check. - See a fix. ### Use It — Find the Bug Students use the tool. #### 👩‍🏫 Teacher Moves - Work through the buggy programs. - Have students find the bug first. - Explain the fix each time. #### 🎒 Student Actions - Find each bug. - Explain the fix. - Check the reasoning. ### Create — Debug a Program Students create/fix. #### 👩‍🏫 Teacher Moves - Give buggy programs (or grid robot). - Have students find and fix the bug. - Then break and swap with a partner. #### 🎒 Student Actions - Fix a buggy program. - Test the fix. - Debug a partner’s. ### Share — Share Students share a fix. #### 👩‍🏫 Teacher Moves - Invite a bug-and-fix story. - Normalize mistakes as learning. - Hand out the exit ticket. #### 🎒 Student Actions - Share a bug and fix. - Explain the check they used. - Complete the exit ticket. ## Built to the standards you report on Aligned to the ISTE Standards for Students and the CSTA K-12 Computer Science Standards. Debug (identify and fix) errors in an algorithm or program that includes sequences and simple loops. Test and debug a program or algorithm to ensure it runs as intended. Test solutions and troubleshoot to improve them. Describe steps in a procedure using sequence language. ## One lesson, every learner ### Multilingual Learners - Highlight the buggy step in color. - Sentence frame: “The bug is ___. It should be ___.” - Walk a buggy path to see the error. ### Support & Access - Give programs with one obvious bug. - Offer two choices instead of three. - Fix one step at a time and re-run. ### Stretch & Extend - Find and fix two bugs in one program. - Explain why the computer isn’t “wrong.” - Write a buggy program for a friend to fix. ### What to gather - 📽️Projector / board - 📓Notebooks - 💻Find the Bug - 🔍Buggy-program cards - ✏️Pencils - 🎫Exit-ticket slips ### Key terms - **bug**: a mistake in a program - **debug**: to find and fix a bug - **error**: something that went wrong - **test**: to run and check a program - **fix**: to correct a mistake - **program**: a sequence of commands - **trace**: to follow a program step by step - **persevere**: to keep trying when it’s hard ## Exit Ticket Preview the three formative checks. Tap “Sample answer” to see what mastery looks like — hide them before you print for students. ### Going deeper? Bug swap. Have students write a working program, add one bug on purpose, then trade and race to find each other’s bug. A printable bug-swap card is in the CS library. ## Check your understanding **1. What does “bug” mean?** - a mistake in a program *(correct)* - to follow a program step by step - to correct a mistake - a sequence of commands “bug” means: a mistake in a program **2. Which word means: “to find and fix a bug”?** - debug *(correct)* - program - test - bug “debug” means: to find and fix a bug **3. What does “error” mean?** - something that went wrong *(correct)* - to correct a mistake - to find and fix a bug - to keep trying when it’s hard “error” means: something that went wrong **4. Which word means: “to run and check a program”?** - fix - test *(correct)* - persevere - program “test” means: to run and check a program **5. What does “fix” mean?** - a mistake in a program - to correct a mistake *(correct)* - to run and check a program - to keep trying when it’s hard “fix” means: to correct a mistake **6. Which word means: “a sequence of commands”?** - persevere - error - fix - program *(correct)* “program” means: a sequence of commands ## Printable worksheet --- Full lesson page: https://lessonplans.k12academics.com/k12-lesson-debugging.html All lessons: https://lessonplans.k12academics.com/