Zero to Hero path · Stage 1 of 4

0%

SKIP TO CONTENT

Make It Do Something: Your First Interaction

beginner~12 min0/4 steps

Make It Do Something

Your profile card looks great — but it just sits there. Click it, poke it, nothing happens. That's because HTML is structure and Tailwind is style. Behavior is the job of JavaScript.

Here's the secret nobody tells beginners: in vibe coding, you don't memorize JavaScript. You describe what should happen, and AI writes the code. Behavior is just a sentence:

"When someone clicks the like button, the number next to the heart goes up by 1."

Give that prompt to AI, and it produces something tiny like this:

const btn = document.getElementById("like-btn");
btn.addEventListener("click", () => {
  likes = likes + 1;
  count.textContent = likes;
});

That's it. Three moves, every time:

  1. Find the element (getElementById)
  2. Listen for an event (addEventListener("click", ...))
  3. Change something (textContent, a class, anything)

Find, listen, change. Almost every interaction on every website you've ever used — dropdowns, dark mode toggles, like buttons — is some version of this pattern.

In this lesson you'll add a like counter to your card. By the end, you'll click a heart and watch a number you control go up. That's the moment a page becomes an app.

Instructions

1

Add a <button id="like-btn"> below the CTA link, with a heart emoji and a <span id="like-count">0</span> inside it

Hint: Try: `<button id="like-btn" class="mt-4 w-full flex items-center justify-center gap-2 bg-white/10 hover:bg-white/20 border border-white/20 font-bold py-3 rounded-xl transition-all">❤️ <span id="like-count">0</span></button>`

2

Add an empty <script> tag just before </body> — this is where the behavior lives

3

Inside the script, grab both elements: the button and the counter. Use document.getElementById with the ids you gave them

4

Listen for clicks: addEventListener("click", ...) on the button — increase likes by 1 and update the counter's textContent

Your Code

html
49 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

Live Preview

Live Preview