Lesson 17 ยท about 20 minutes ยท Vibe Coding Mastery
๐ Read AI Code Like a Detective
The AI hands you a file with 80 lines of code. Do you read it top to bottom like a book? NO WAY. Detectives don't read every page of the phone book โ they follow clues. Today you learn the Detective Method that works on ANY file, forever.
๐ฌ Watch first (90 seconds)
Secret #1: AI code is never random
Here's the big secret that makes all AI code way less scary: the AI builds the same house skeleton YOU already know. A hero at the top, some sections, buttons with ids, a <script> at the bottom with the find-the-brick โ listen-for-click โ change-a-brick spell. You built that skeleton yourself in lessons 9 and 10! The AI just types it faster and adds more decoration.
So when a big AI file lands in front of you, you're not exploring an alien planet. You're walking into a house built from a blueprint you've seen before.
- Skim the body first, top to bottom. Ignore the details โ just read the tags. "Header... hero... section... section... footer... script." You're asking: what rooms does this house have?
- Find the names. Every
classandidis a label the AI chose to be readable:class="hero",id="menu-btn",class="price-card". Names ARE documentation. Read the names, and the code explains itself. - Follow ONE thread. Pick one button. Note its
id. Jump to the<script>at the bottom. FindgetElementByIdwith that same id. Boom โ now you know exactly what clicking that button does. One thread at a time, never the whole spiderweb. - Expect strangers. AI code WILL contain things you haven't learned yet. That's normal FOREVER โ even 20-year pros meet strangers in code every week. Don't panic and don't skip the whole file. Zoom in on ONE stranger and ask the AI: "explain this line like I'm 10."
Meet today's stranger: classList ๐ท๏ธ
Let's practice move #4 right now on a stranger that shows up in TONS of AI code:
panel.classList.add("open"); // stick the "open" sticker on
panel.classList.remove("open"); // peel the "open" sticker off
panel.classList.toggle("open"); // no sticker? stick it. sticker? peel it.
In kid language: classList gives or takes away a class sticker. Why does that matter? Because your CSS can say "anything wearing the open sticker is visible" โ so adding or removing the sticker makes different CSS rules apply. One line of JavaScript, and the whole look changes. This is how almost every menu, popup, and dark-mode switch on the internet works!
.toggle("open") in a script? Immediately hunt for .open in the CSS. The script and the CSS are partners in crime โ the script flips the sticker, the CSS decides what the sticker DOES.
๐ ๏ธ Build it (the fun part)
- Open
practice/prompted.html(your lesson 16 page) in VS Code. No prompted.html? Usepractice/ai-landing.htmlfrom lesson 10 instead. - Move 1 โ list the rooms. Skim ONLY the body, top to bottom, reading just the tags. On paper, write the rooms in order, like: header โ hero โ features โ prices โ footer โ script.
- Move 2 โ collect 5 names. Write down 5 classes or ids you find, and next to each, your guess of what it's for.
class="price-card"โ "a card showing a price". Easy, right? The names tell you! - Move 3 โ follow one thread. Pick ONE button in the body. Write its
id. Scroll to the script. Find thegetElementByIdwith that id. Read that handler and write one sentence: "When I click ___, the code ___." - Move 4 โ circle one stranger. Find ONE line you don't understand. Circle it on paper. Then ask your AI teacher: "Explain this line like I'm 10: [paste the line]". Write the answer in your own words โ now the stranger is a friend.
- Read your paper back. You just understood an AI file WITHOUT reading every line. That's the pro move. ๐ต๏ธโโ๏ธ๐
๐น๏ธ Try it right here โ the lesson checks your code!
Good news: THESE preview boxes have their electricity ON โ buttons really click! Bad news for lazy detectives: the tasks only pass if you truly understood the code. ๐
๐จ Now break it!
Play in Task A's editor โ predict BEFORE you look at the preview!
- In the CSS, change
.panel.opento.panel.opened(don't touch the script). Click the toggle button. The sticker still flips on and off โ but nothing appears! The script and CSS stopped speaking the same name. Fix it back. - Change
classList.toggletoclassList.add. Now the button can OPEN the panel but can never close it. Toggle = flip, add = one-way. Fix it back. - Rename the button's id in the HTML but not in the script. Dead button, silent failure โ your old friend from lesson 8. The thread is cut!
๐ฎ Quiz time
No peeking at the notes above โ trying to remember is what makes it stick!
๐ Want more?
add, remove, and toggle like old friends.