“Double or Take” is a fascinating social experiment game that demonstrates human psychology around risk, greed, and altruism. Players face a simple choice: “Take” the current amount (resetting it to $1) or “Double” it for the next person. The game creates a digital prisoner’s dilemma where individual gain conflicts with collective benefit, while tracking all player actions in real-time through Firebase integration.
doubletake/
└── index.html # Complete social experiment application
// Main game data storage
const firebaseConfig = {
apiKey: "AIzaSyCGd5kWto7J4_0e594SpM5JFeXu2-B4GOE",
authDomain: "joshbruceonline-general.firebaseapp.com",
databaseURL: "https://joshbruceonline-general-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "joshbruceonline-general",
storageBucket: "joshbruceonline-general.appspot.com",
messagingSenderId: "348797894179",
appId: "1:348797894179:web:9c8c8c8dcf8f0b06507b96"
};
const dbRef = firebase.database().ref("doubletake");
const mainValueRef = firebase.database().ref("mainValue");
// Page control and redirect system
const switchFirebaseConfig = {
apiKey: "AIzaSyCRPBjKJfKoLO52TqROpQ3I9X-nEL-0btE",
databaseURL: "https://joshbruceonline-switch-default-rtdb.europe-west1.firebasedatabase.app/",
authDomain: "joshbruceonline-switch.firebaseapp.com",
projectId: "joshbruceonline-switch",
storageBucket: "joshbruceonline-switch.appspot.com",
messagingSenderId: "592073701037",
appId: "1:592073701037:web:309eb7bed49885153a7824"
};
const switchApp = firebase.initializeApp(switchFirebaseConfig, 'switch');
const switchPageRef = switchDb.ref('doubletake');
const redirectLinkRef = switchDb.ref('redirectLink');
// Simple but powerful game mechanics
function handleTake() {
// Player takes current amount, resets to $1
dbRef.push({
action: "take",
userName: userName,
time: new Date().toLocaleTimeString(),
date: new Date().toLocaleDateString(),
value: 1 // Always resets to $1
});
updateMainValue(1);
currentValue = 1; // Global reset
}
function handleDouble() {
// Player doubles amount for next person
dbRef.push({
action: "double",
userName: userName,
time: new Date().toLocaleTimeString(),
date: new Date().toLocaleDateString(),
value: currentValue * 2 // Exponential growth
});
updateMainValue(currentValue); // Maintain doubled amount
}
// Real-time listener for latest game action
dbRef.orderByKey().limitToLast(1).on("child_added", (snapshot) => {
const data = snapshot.val();
if (data) {
currentValue = data.value || 1;
lastAction = data.action || "";
valueElement.textContent = `$${formatNumberWithCommas(currentValue)}`;
updateSentence(lastAction, data.userName || "", data.time || "", data.date || "");
}
});
// Comprehensive action logging
const actionRecord = {
action: "take" | "double", // Player choice
userName: "PlayerName", // Public attribution
time: "HH:MM:SS AM/PM", // Local time stamp
date: "MM/DD/YYYY", // Date stamp
value: currentValue // Amount at time of action
};
body {
font-family: "Helvetica", sans-serif;
font-weight: bold;
text-align: center;
height: 100vh;
margin: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-image: url("https://graffitiwallpaper.com/pics/listings/373_portrait.jpg");
background-size: cover;
background-position: center;
}
.container {
background-color: rgba(128, 128, 128, 0.45); /* Semi-transparent overlay */
padding: 20px;
border-radius: 10vh; /* Rounded design */
display: flex;
justify-content: space-between;
align-items: center;
margin: 25vh; /* Centered positioning */
}
/* Large circular action buttons */
.button {
padding: 10px;
font-size: 36px;
cursor: pointer;
border-radius: 50%; /* Perfect circles */
width: 20vh;
height: 20vh;
margin: 40px;
}
#takeButton {
background-color: #4CAF50; /* Green for "take" */
color: white;
}
#doubleButton {
background-color: #008CBA; /* Blue for "double" */
color: white;
}
#valueContainer {
font-size: 100px; /* Prominent money display */
color: white;
margin: 0px;
}
#sentence {
background-color: rgba(128, 128, 128, 0.5);
padding: 20px;
border-radius: 5vh;
margin-top: 10px;
font-size: 36px;
color: white;
}
// Professional number formatting with commas
function formatNumberWithCommas(number) {
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// Display with currency formatting
valueElement.textContent = `$${formatNumberWithCommas(currentValue)}`;
function updateSentence(action, userName, time, date) {
if (action === "take") {
sentenceElement.textContent = `The amount was last taken by ${userName} at ${time} on ${date}.`;
} else if (action === "double") {
sentenceElement.textContent = `The amount was last doubled and given by ${userName} at ${time} on ${date}.`;
}
}
// Listen for administrative page control
switchPageRef.on('value', (snapshot) => {
const isPageActive = snapshot.val();
if (isPageActive === false) {
// Page has been remotely disabled
redirectLinkRef.once('value', (snapshot) => {
const redirectLink = snapshot.val();
if (redirectLink) {
window.location.href = redirectLink; // Custom redirect
} else {
window.location.href = 'https://joshbruce.online/backrooms'; // Default fallback
}
});
}
});
function handleTake() {
const userName = prompt("Enter your name:");
if (userName) { // Basic validation
// Record action with full attribution
dbRef.push({...actionData});
// Update display immediately
valueElement.textContent = `$${formatNumberWithCommas(currentValue)}`;
}
// No action if user cancels prompt
}
orderByKey().limitToLast(1) for latest action// Basic user input handling
const userName = prompt("Enter your name:");
if (userName) {
// Proceed with action
}
// Implicit validation: empty/null names prevent action
// Each "double" action follows: new_value = current_value × 2
// Progression examples:
// Start: $1
// After 1 double: $2
// After 2 doubles: $4
// After 3 doubles: $8
// After 10 doubles: $1,024
// After 20 doubles: $1,048,576
// After 30 doubles: $1,073,741,824 (over $1 billion)
/* Responsive design considerations */
.button {
width: 20vh; /* Viewport-based sizing */
height: 20vh;
font-size: 36px; /* Large touch targets */
}
#valueContainer {
font-size: 100px; /* Readable on small screens */
}
Double or Take represents a masterfully designed social experiment that transforms abstract game theory concepts into an engaging, real-time interactive experience. The application successfully creates a digital environment for studying human behavior around risk, trust, and social cooperation.
Technical Rating: 8.6/10
The application serves as both an entertaining game and a valuable tool for understanding human psychology, making complex economic and social concepts accessible through interactive gameplay.