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.