Free

Memory Card Game

A concentration game built around the three states that stop fast clicks breaking the board.

  • JavaScript
  • CSS
  • HTML

About this project

Flip two cards, keep them if they match, turn them back if they do not. Three board sizes, a move counter, a timer, and a CSS 3D flip.

The game itself is easy. Making it survive a player who clicks faster than the animation is the part worth learning, and it is the reason this project exists. The board is always in exactly one of three states — nothing flipped, one flipped, two flipped and locked — and the current state is displayed on screen while you play, so the mechanism is visible rather than merely described.

Most tutorial versions of this game guard the race with a scattering of boolean flags. That works until it does not: a fourth click landing in the wrong window can leave a card matched against itself, and the README walks through the exact timing that breaks it, with the millisecond figures measured rather than guessed.

What you will learn

  • Model a UI as an explicit state machine instead of a pile of boolean flags
  • Understand why a click during an animation is a real bug and how a LOCKED state removes it
  • Shuffle correctly with Fisher-Yates, and see measured evidence that sort() with a random comparator is biased
  • Build a CSS 3D card flip with transform-style and backface-visibility
  • Keep a game accessible: live-region announcements, a labelled dialog, and a board taken out of the tab order when it is covered

Before you start

  • JavaScript basics — arrays, functions and events
  • A browser and a text editor. Nothing to install.

New to JavaScript? The free JavaScript course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.