Skip to content

Instantly share code, notes, and snippets.

@lewdev
Created August 20, 2026 01:34
Show Gist options
  • Select an option

  • Save lewdev/1632811c5639e664c6ff3c1799a9da4a to your computer and use it in GitHub Desktop.

Select an option

Save lewdev/1632811c5639e664c6ff3c1799a9da4a to your computer and use it in GitHub Desktop.
🏁 Emoji Car Race
<style>:root{color-scheme:dark}
div {
margin-left: 100px;
transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}
</style>
<h1>🏁 Emoji Car Race</h1>
A super simple racing simulation game for fun and learning.
<p id=o></p>
<script>
const CARS = [..."πŸš“πŸš•πŸš—πŸš™πŸ›»πŸššπŸš›πŸš’πŸšπŸš‘πŸšŒπŸšœπŸšπŸšƒπŸš‹"];
const RACE_DISTANCE = 200;
const SPEED = 2;
const racers = [];
// initialize
for (i = CARS.length; i--;) racers.push({
emoji: CARS[i],
distance: 0,
});
let winner = null;
const restart = () => {
for (const racer of racers) racer.distance = 0;
winner = null;
loop();
};
const loop = () => {
if (!winner) {
for (const racer of racers) {
racer.distance += Math.random() * SPEED;
}
for (const racer of racers) {
if (racer.distance >= RACE_DISTANCE) winner = racer;
}
setTimeout(loop, 16);
}
o.innerHTML = (winner ? `<h2>${winner.emoji} Wins! <button onclick="restart()">πŸ”„οΈ Restart</h2>` : "")
+ racers.map(({emoji, distance}) => `<div style="margin-left: ${RACE_DISTANCE - distance}px">${emoji}</div>`).join``;
};
loop();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment