Skip to content

Instantly share code, notes, and snippets.

@danjohnson95
Last active November 13, 2025 08:44
Show Gist options
  • Select an option

  • Save danjohnson95/f7e4538de475a4fe8ee8abab2a023615 to your computer and use it in GitHub Desktop.

Select an option

Save danjohnson95/f7e4538de475a4fe8ee8abab2a023615 to your computer and use it in GitHub Desktop.
A Formula 1 style reaction game, coming in at under 1kb
<!-- http://pico.lat/Y6Gez --><style>body{background:#111;color:#fff;text-align:center}#l{display:flex;justify-content:center;gap:10px;margin:30px 0}#l p{width:60px;height:60px;border-radius:50%;background:#333;border:2px solid #666}.on{background:red!important}#r{font-size:24px}#i{color:#888;margin:10px 0}</style><div id=l><p><p><p><p><p></div><div id=i>Press any key to start</div><div id=r></div><script>let t,s,f=0,d=document,q="getElementById",ht="innerHTML",fE="forEach",kd="onkeydown",cN="className",m=Math,dt=Date,sT=setTimeout,res=d[q]("r"),inf=d[q]("i");function st(){if(s)return;s=1,f=0,res[ht]="",inf[ht]="Wait for lights...";let e=d.querySelectorAll("#l p");e[fE]((t=>t[cN]=""));let n=0;!function r(){n<5?(e[n++][cN]="on",sT(r,800*m.random()+400)):sT((()=>{f||(e[fE]((t=>t[cN]="")),inf[ht]="GO! Press any key!",t=dt.now(),d[kd]=()=>{if(f)return;f=1,s=0;let e=dt.now()-t;res[ht]=e+"ms",inf[ht]="Press any key to restart",d[kd]=st})}),2e3*m.random()+1e3)}()}d[kd]=st;</script>
@danjohnson95
Copy link
Author

Test your reactions with this Formula 1 style reaction game. Press any key to start, and once all the reds go out, press any key as quick as you can.

Have a look through the revisions of this Gist to get an idea of how I got this so small! No AI, just some crazy ideas, ending up at just 989 bytes 🤌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment