JavaScript Game Programming: Inside Our Memory Game
A memory game looks simple until someone taps faster than its animations. Two cards should be open, a pair should count once, and a new round should start cleanly. Those small promises are where JavaScript game architecture becomes visible to the player.
Our Cockatiel Memory browser game is a practical example. It runs with HTML, CSS and JavaScript, and separates the rules of a round from the interface that displays it. This walkthrough explains that separation and its trade-offs through behaviour and diagrams. It leaves the implementation private.

Captured from the playable browser game on 1 December 2026. One card is open; the interface asks the player to choose a second.
Three responsibilities behind one board
The game has three useful responsibilities to distinguish. The rules describe the current round and decide whether an action is valid. The interface displays cards, counters and messages. Browser storage keeps personal best results on that device.
The rules do not need to know where a button sits or which colour its border uses. The interface does need to know whether a card is face down, temporarily revealed or permanently matched. Keeping those concerns separate makes it possible to reason about a round without first reproducing every visual effect.
An overview of the existing browser game. The local-records branch represents best results, not cloud saves or a saved in-progress board.
A useful consequence is that a change to card styling should not alter the matching rule. Conversely, a rules check should not depend on whether a transition has finished drawing. The architecture creates a place for each decision instead of allowing the page's appearance to become the only record of what happened.
Follow one turn from tap to feedback
Start with a new Easy round: twelve cards contain six pairs. The first accepted tap reveals one card. There is no pair to compare yet, so the move counter stays unchanged and the message asks for a second choice.
The second accepted card completes an attempt. A matching pair stays revealed and increases the pair total. A mismatch stays visible briefly before both cards close. That interval lets the player actually see and remember the failed attempt.
The important boundary is the mismatch interval. Further taps are ignored while the pair is waiting to close. Without that boundary, a third card could appear while the previous comparison still needs to finish, leaving the player unsure which two cards belong to the same attempt.
Tapping the same open card again also does not create a new attempt. Neither does tapping an already matched card. These are small interaction rules, but they make the counters and the visible board tell the same story.
Why a timer needs its own lifecycle
There are two different kinds of time in this game. The round timer measures elapsed play after the first accepted card. The mismatch delay determines how long two different faces remain visible. They answer different questions and should not be treated as one mechanism.
A restart clears the active timer and any outstanding mismatch delay before creating the next round. Otherwise a callback from the previous board could arrive after the player has already started again. The same concern applies when changing difficulty: the new round should have its own deck, counters and messages.
Reduced-motion handling also changes the mismatch interval in the current interface. That makes the waiting behaviour worth checking as an interaction, rather than assuming a single timing choice proves the experience works for everyone.
Difficulty changes the amount to remember
Easy uses six pairs, Medium eight and Hard twelve. The underlying idea stays the same, while the amount of information and the board layout change. This gives the player a familiar action at each level instead of introducing a different matching system for every difficulty.
The timer and move count provide feedback, and the completed round awards stars. They should describe performance without confusing it with the rules for accepting a card. A fast click does not make an invalid action valid.
Test rules and test the experience
Rules can be checked with repeatable arrangements: open a known pair, try a mismatched pair, tap during the waiting interval and confirm the round finishes only after all pairs are found. These checks are useful because the expected outcome is clear.
A separate browser check asks different questions. Is the card face large enough to recognise? Is the message readable on a phone? Can someone use the controls with a keyboard? Does a restart feel immediate? Passing a logic check cannot answer those questions on its own.
That distinction guides the studio's development work: use precise checks for predictable rules, then inspect the experience those rules create. The article explains the approach without publishing the engine or its full test suite.
Best results belong to this browser
The current game keeps best results locally. It does not need an account to play, and these records are not a cross-device leaderboard. Clearing browser data can remove them.
This boundary matters when describing architecture publicly. A local personal-best feature should not be presented as a cloud service. It also keeps this small browser game understandable: the player can open the page and start a round without navigating an account flow.
Play Cockatiel Memory to follow the interaction yourself. For a different kind of state change, try Flock Sort, or read how bird-game design connects the mechanics to the flock.
