Skip to content

The Only 3 Concepts You Need

Master Events, State, and Conditionals through our traffic light system. These three concepts power every website — from simple buttons to Instagram and ChatGPT.

⚡

Events = Things That Happen

User actions that trigger responses

Button clicked (user trigger)

onClick → changeLight()

Timer fires (automatic trigger)

every 5s → nextLight()
🧠

State = Things to Remember

Information your app keeps track of

Current light color

lightState = “red”

Timer countdown

timer = 0
🔀

Conditionals = If This, Then That

Rules that determine outcomes

Timer reaches zero

if timer = 0 → switch

Light sequence

red → green → yellow → red

Interactive Demo

Click the buttons and watch the concepts work together

MANUAL

What's Happening

EVENT (What triggered)

Click a button…

STATE (What's remembered)

  • • light: “red”
  • • mode: “manual”

CONDITIONAL (Rules checking)

  • ○ if timer = 0 → change light

That's it! Every website uses these same patterns. When you click “Like” on Instagram: Event (click) → State (liked: true) → Conditional (if liked, show filled heart).

Why This Helps Your Prompts

Before: Vague

❌ “Make a button that does something”

After: Precise

✓ “When user clicks Submit (event), save the form data (state), and if successful (conditional), show a success message”

When Debugging

Ask yourself:

  • ⚡Event issue? Is the trigger firing?
  • 🧠State issue? Is the right value stored?
  • 🔀Conditional issue? Is the logic correct?

Ready to Build?

Now that you understand the fundamentals, put them into practice.