Behavioral economics studies how people actually make decisions about money, time and risk, as opposed to how a perfectly rational agent would. Most of its core paradigms share a convenient property: they are sequences of choices between clearly described options, presented as text and buttons. They rarely depend on millisecond timing or precise visual control, which makes them among the easiest experiments to move online without losing anything that matters.
The following code presents a series of choices between a smaller immediate amount and a fixed larger amount at a delay. Each trial records both amounts, the delay and which option was chosen, which is everything you need to fit a discount function afterwards. The left/right position of the options is randomized on every trial to avoid a side bias.
const jsPsych = initJsPsych();
const later = 100;
const delays = [7, 30, 90, 180, 365];
const nowAmounts = [10, 25, 40, 55, 70, 85, 95];
const choices = [];
for (const delay of delays) {
for (const now of nowAmounts) {
choices.push({ now, delay });
}
}
const choiceTrial = {
type: jsPsychHtmlButtonResponse,
stimulus: "<p>Which would you prefer?</p>",
choices: () => {
const now = jsPsych.evaluateTimelineVariable("now");
const delay = jsPsych.evaluateTimelineVariable("delay");
return [`$${now} today`, `$${later} in ${delay} days`];
},
data: {
task: "delay_discounting",
now_amount: jsPsych.timelineVariable("now"),
later_amount: later,
delay_days: jsPsych.timelineVariable("delay")
},
on_finish: (data) => {
// response is 0 for the left button, 1 for the right button
data.chose_later = data.response === 1;
}
};
const timeline = [
{
type: jsPsychInstructions,
pages: [
"<p>You will see pairs of options. Click the one you would rather have.</p>" +
"<p>One of your choices will be selected at random and paid as a bonus.</p>"
],
show_clickable_nav: true
},
{
timeline: [choiceTrial],
timeline_variables: choices,
randomize_order: true
}
];
jsPsych.run(timeline);
Because choices is a function here, it uses jsPsych.evaluateTimelineVariable() (the jsPsych 8 form); the data object uses jsPsych.timelineVariable() directly, which works when passed as a parameter. If you want side randomization as well, store a later_on_right flag in data, swap the button labels accordingly, and compute chose_later from both values in on_finish. With 35 choices, the indifference point at each delay can be estimated as the midpoint between the largest immediate amount rejected and the smallest accepted, and a hyperbolic k fitted across delays.
Real incentives. Experimental economics has a strong norm against hypothetical payoffs, and for good reason: behavior in games changes when money is at stake. Online, the standard solution is to pay a base fee plus a bonus determined by one randomly selected trial. Prolific supports bonus payments per participant, and because Cognition records URL parameters such as PROLIFIC_PID as a column on every trial, computing each participant's bonus from the exported CSV is straightforward. See our guide on Prolific, SONA and MTurk integration.
Randomization and counterbalancing. Randomize trial order (as above), randomize which side each option appears on, and if you compare framings or endowments between participants, assign them to conditions in a balanced way. Cognition balances between-subject conditions on the server and exposes the assignment as window.CONDITION, so you can branch your timeline on it without writing your own allocation logic.
Partners and deception. Multi-player games are usually run online with simulated partners or with pre-recorded decisions from earlier participants. Economics journals generally prohibit deceiving participants, while psychology permits it with debriefing; decide which norm applies to your venue before you design the task, and describe the partner honestly in the consent text if you can. Cognition's consent page accepts markdown and sends participants who decline to a URL of your choosing.
Attention and comprehension. Include a comprehension check after the instructions (for example, "If you choose the right option, how much will you receive and when?") and record it in the data so you can exclude participants who failed it, according to criteria you set in advance.
To run the example, create a free account, paste the code into the editor, select jsPsych 8.2.3, and copy the participant link into your Prolific study. Each choice is saved to the server the moment it is made, data can be exported as CSV or JSON, single-use links prevent repeat participation, and recruitment can be capped at a fixed number of participants. The free plan covers four tasks with sixty participants each, which is enough to pilot a discounting or dictator task before committing a budget to it. The documentation describes the data format and the conditions feature in detail.