Lesson 325 of 1169
Use AI to Fix Code That Does Not Work
When your code breaks, AI is amazing at finding the problem. Way faster than just staring at it.
Explorers · AI-Assisted Coding · ~24 min read
The big idea
When your code does not work, do not just stare at it. Show it to AI. AI is amazing at spotting bugs — typos, missed brackets, logic errors.
Some examples
- 'My code does not run. Here is the error message and the code.'
- 'My code runs but does not do what I expected. What went wrong?'
- 'I think my loop is wrong. Help me see why.'
- 'Why does this work for some inputs but not others?'
Try it!
Next time your code breaks, paste it into AI with the error. Notice how fast AI spots the issue.
The best way to describe a bug to AI
Showing broken code to AI is like taking a sick plant to a gardener — the more info you give, the better the diagnosis. Just pasting code and saying 'it doesn't work' rarely gives the best results. The magic formula is three parts: the code itself, the exact error message, and what you expected to happen versus what actually happened. 'My Python says NameError: name x is not defined on line 7, but I already defined x on line 3' gives AI everything it needs to spot that you defined x inside a function and then tried to use it outside (a scope problem). Without that context, AI has to guess. Beyond fixing bugs, AI can also explain why the bug happened and how to avoid the same type of error in the future. This is how good coders learn — not just by fixing the current bug, but by understanding the category of mistake so they can recognize it faster next time.
- Always include the exact error message — don't paraphrase it
- Paste the smallest chunk of code that reproduces the bug, not your entire project
- Tell AI what you expected to happen and what actually happened instead
- After the fix, ask 'why did this error happen?' to learn the concept, not just the answer
Key terms in this lesson
End-of-lesson quiz
Check what stuck
8 questions · Score saves to your progress.
Lesson help
Questions are best handled with a grown-up here.
For this age range, Tendril keeps freeform AI chat paused until parent/guardian consent and child-safe moderation are fully verified. Use the quiz, notes, and related lessons below, or ask a parent, guardian, teacher, or librarian to work through the question with you.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Explorers · 40 min
How AI Helps Make Sure Code Actually Works
AI can write 'tests' — little checks that make sure your code does what you want.
Explorers · 29 min
AI Can Translate Scary Error Messages
AI turns weird coding errors into kid-friendly fixes.
Explorers · 7 min
AI Can Help You Find Bugs in Code
Show AI broken code and it will help find the bug, like a code doctor.
