Lesson 18 ยท Vibe Coding Mastery ยท about 20 minutes
๐ Debug With AI (and Beat It to the Fix)
Vibe-coded pages break. That's not bad luck โ that's Tuesday. Today you learn the pro loop for hunting bugs, and how to ask AI for help like a detective instead of crying "it doesn't work ๐ญ".
๐ฌ Watch first (90 seconds)
Every page breaks. Pros don't panic.
You've vibe-coded whole pages with AI. Awesome. But sooner or later you press refresh and... the button is dead. The colors are gone. Half the page vanished. This happens to EVERY coder on Earth, every single day.
The difference between a beginner and a pro is not "pros make no bugs". It's this: beginners panic, pros follow a loop.
- LOOK ๐ โ What EXACTLY is wrong on screen? Not "it's broken" โ be precise: "the Buy button does nothing when I click it."
- CONSOLE ๐ โ Right-click the page โ Inspect โ Console tab. Red text is the browser naming the crime scene โ and it even gives you a line number! That's the browser saying "the trouble is HERE."
- GUESS ๐ต๏ธ โ Which of the 3 usual suspects is it?
- Spelling mismatch โ
buyvsbuyy,.cardvs.cards. Computers never guess what you meant. - Missing closer โ a forgotten
</div>,}, or). One missing closer can swallow half your page. =vs===โ one=PUTS a value in a box, three===ASKS "are these the same?". Mix them up and yourifgoes crazy.
- Spelling mismatch โ
- FIX or REPORT ๐ ๏ธ โ Try YOUR fix first. Can't crack it in 2 minutes? Then write a proper bug report and send it to your AI.
The Bug Report: how pros ask for help
Compare these two messages to an AI:
- โ Bad: "my button doesnt work pls fix ๐ญ" โ the AI has to GUESS what's wrong, and guessing AIs rewrite everything.
- โ Good: "I expected the score to go up when I click. Instead nothing happens. Here is the error from the console: Uncaught TypeError: Cannot set properties of null, line 12. Here is my code: [paste]."
The magic template has four parts:
- I expected... โ what SHOULD happen.
- Instead... โ what ACTUALLY happens.
- Here is the error from the console: [paste the red text]. This is GOLD ๐ โ the console error tells the AI the exact crime and the exact line. ALWAYS paste it.
- Here is my code: [paste the code].
Rule 2 โ Leash the AI. AI sometimes "fixes" a bug by rewriting your WHOLE page โ and breaks three other things you loved. Always add: "Fix ONLY the bug. Change nothing else."
๐ ๏ธ Build it: sabotage practice (break it on PURPOSE)
- Open
practice/clicker.html(your clicker game from lesson 15) in VS Code AND in your browser. Open the Console: right-click โ Inspect โ Console tab. Keep it open the whole time. - Sabotage 1 โ spelling mismatch. Find a
getElementById("...")in your script and misspell the id inside it (like"scor"). Save, refresh, click. Now READ the console: what does the red text SAY, and which line number does it point at? Say it out loud. Then undo (โZ), save, refresh โ game alive again. - Sabotage 2 โ the sneaky
=. Find an===in anifand change it to a single=. Save, refresh, play. Weird behavior? Any console message? (Sometimes this one is SILENT โ the sneakiest bugs don't even leave a red note.) Undo, save, refresh. - Sabotage 3 โ missing closer. Delete one
}from your script. Save, refresh. The console should shout something like Unexpected end of input โ that's browser-speak for "you forgot a closer somewhere!" Note the line number. Undo, save, refresh. - Done? You just read THREE real error messages without panicking. That's a superpower most grown-ups don't have. ๐
๐น๏ธ Try it right here โ the lesson checks your code!
Crime scene 1 is a page an AI wrote with THREE planted bugs โ one in HTML, one in CSS, one in JavaScript. All three are "usual suspects" you already know. Then in the second task you'll write a bug report like a pro.
๐ฎ Quiz time
No peeking at the notes above โ trying to remember is what makes it stick!