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 = 0Conditionals = If This, Then That
Rules that determine outcomes
Timer reaches zero
if timer = 0 β switchLight sequence
red β green β yellow β redInteractive Demo
Click the buttons and watch the concepts work together
What's Happening
EVENT (What triggered)
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
After: Precise
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.