For over 35 years, this card trick has amazed and confused friends and family. It’s a simple trick in execution, but behind the scenes, there’s a clever mathematical principle at play. Here’s a breakdown of how it works and how I brought it to the web.
The game begins with 21 cards arranged into three columns. Here’s the step-by-step breakdown:
I’ve ported this trick to the web, and now it’s available as an interactive game. You can try the game here.
Here’s an overview of how the trick was implemented using JavaScript:
The JavaScript code takes an array of 52 cards and shuffles them. It then selects 21 cards from the shuffled deck and arranges them into three columns. Here’s a snippet that does the shuffle:
function shuffleAndDeal() {
cardImages = [...allCardImages].sort(() => Math.random() - 0.5).slice(0, 21);
dealCards();
}
Each time you select a column, the JavaScript code takes that column and moves it to the middle. This is crucial to keeping your card in the central stack:
function columnSelected(pickedColumn) {
const newOrder = [];
if (pickedColumn === 0) {
newOrder.push(...columns[1], ...columns[0], ...columns[2]);
} else if (pickedColumn === 1) {
newOrder.push(...columns[0], ...columns[1], ...columns[2]);
} else {
newOrder.push(...columns[0], ...columns[2], ...columns[1]);
}
cardImages = newOrder;
}
Once the shuffle has been repeated three times, the 11th card in the deck is revealed as your chosen card:
function revealFinalCard() {
const finalCardIndex = 10; // The 11th card
const finalCardSrc = cardImages[finalCardIndex];
const finalCardElement = document.getElementById('finalCard');
document.getElementById('message').classList.add('show');
finalCardElement.src = finalCardSrc;
finalCardElement.classList.add('show');
}
The card images used in the game are SVG files that you can download from Tek Eye's SVG Playing Cards.
You can download the full code and set of card images here. If you’d like to add this trick to your own website or use it for learning purposes, feel free to experiment with it.
With this explanation, you now know the secret behind this fun, interactive card trick. Try it out with your friends and family, or explore how it works by playing the online version.