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.

๐Ÿ’ก The one idea of this lesson: the pro debugging loop Four steps, always in this order:
  1. LOOK ๐Ÿ‘€ โ€” What EXACTLY is wrong on screen? Not "it's broken" โ€” be precise: "the Buy button does nothing when I click it."
  2. 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."
  3. GUESS ๐Ÿ•ต๏ธ โ€” Which of the 3 usual suspects is it?
    • Spelling mismatch โ€” buy vs buyy, .card vs .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 your if goes crazy.
  4. 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.
Learning to read error messages calmly is the whole game. The red text is not yelling at you โ€” it's a clue, gift-wrapped.

The Bug Report: how pros ask for help

Compare these two messages to an AI:

The magic template has four parts:

  1. I expected... โ€” what SHOULD happen.
  2. Instead... โ€” what ACTUALLY happens.
  3. 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.
  4. Here is my code: [paste the code].
โš ๏ธ Two pro rules Rule 1 โ€” Try YOUR fix first (2 minutes). Run the loop yourself before asking. If you fix it โ€” you WIN, and your brain levels up. If you don't โ€” no shame, your bug report is now super sharp because you already looked at the console. Ask-first kids get dependent; try-first kids get smart.

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)

๐Ÿงช Your mission You're going to break your own clicker game 3 different ways โ€” one at a time โ€” and read what the console says each time. Firefighters practice on fires they lit themselves. So do debuggers.
  1. 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.
  2. 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.
  3. Sabotage 2 โ€” the sneaky =. Find an === in an if and 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.
  4. 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.
  5. 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!

๐Ÿ“š Want more?

โญ Best thing to read next MDN: What went wrong? Troubleshooting JavaScript โ€” Mozilla's official guide to reading error messages, with a broken number-guessing game you get to fix. Reading it counts as a lesson block! Keep the JS Cheat Sheet nearby, and the Glossary if a word looks alien.