In a lexical decision task (LDT) participants see a string of letters and must decide, as quickly and accurately as possible, whether it is a real word in their language (table) or a non-word (dnfke). The response is usually a key press, and the two dependent measures are reaction time and accuracy on the word trials. Non-words are typically pronounceable and orthographically legal (glort rather than xqzpt) so that the decision cannot be made on superficial features alone.
The task is popular because it is simple to explain, takes only a few minutes, and gives a sensitive index of how quickly a word is retrieved from the mental lexicon. It is one of the workhorse methods of psycholinguistics and of research on reading, bilingualism and memory.
##### and the target, so that participants are usually unaware of it. It is widely used to study early orthographic and morphological processing.Press W if the letter string is a word and N if it is not. You have 1.5 seconds for each string.
The embedded demo runs on an earlier version of jsPsych. The code below is the equivalent version written for jsPsych 8 (it also runs on jsPsych 7). It shows a 500 ms fixation cross before each string, presents the strings in random order, and scores each response with compareKeys.
const jsPsych = initJsPsych({
on_finish: () => {
jsPsych.data.displayData();
}
});
const timeline = [];
// Instructions
const instructions = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "<p>In this task, you will see a series of letter strings.</p>" +
"<p>Press <strong>W</strong> if the string is a word, and <strong>N</strong> if it is not a word.</p>" +
"<p>Press any key to begin.</p>",
post_trial_gap: 500
};
timeline.push(instructions);
// Stimuli: words and pronounceable non-words
const stimuli = [
{ stimulus: "table", word: true },
{ stimulus: "chair", word: true },
{ stimulus: "house", word: true },
{ stimulus: "water", word: true },
{ stimulus: "dnfke", word: false },
{ stimulus: "glort", word: false },
{ stimulus: "prane", word: false },
{ stimulus: "slint", word: false }
];
// Fixation cross shown before every string
const fixation = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "<p style="font-size: 40px">+</p>",
choices: "NO_KEYS",
trial_duration: 500,
data: { task: "fixation" }
};
// The lexical decision itself
const ldt = {
type: jsPsychHtmlKeyboardResponse,
stimulus: () => "<p style="font-size: 40px">" + jsPsych.evaluateTimelineVariable("stimulus") + "</p>",
choices: ["w", "n"],
trial_duration: 1500,
data: {
task: "ldt",
string: jsPsych.timelineVariable("stimulus"),
word: jsPsych.timelineVariable("word")
},
on_finish: (data) => {
const expected = data.word ? "w" : "n";
data.correct = jsPsych.pluginAPI.compareKeys(data.response, expected);
}
};
timeline.push({
timeline: [fixation, ldt],
timeline_variables: stimuli,
randomize_order: true
});
// Feedback at the end
const debrief = {
type: jsPsychHtmlKeyboardResponse,
stimulus: () => {
const trials = jsPsych.data.get().filter({ task: "ldt" });
const accuracy = Math.round(trials.filter({ correct: true }).count() / trials.count() * 100);
const rt = Math.round(trials.filter({ correct: true }).select("rt").mean());
return "<p>Accuracy: " + accuracy + "%. Mean RT on correct trials: " + rt + " ms.</p>" +
"<p>Press any key to finish.</p>";
}
};
timeline.push(debrief);
jsPsych.run(timeline);
A trial with no response within 1500 ms has response and rt set to null and is scored as incorrect. To turn this into a priming experiment, add a prime trial (a short jsPsychHtmlKeyboardResponse with choices: "NO_KEYS") between the fixation and the target, and add a prime and relatedness field to each entry in stimuli. For a frequency study, add a frequency field so that you can split the RTs by condition when analysing.
Paste the code into the Cognition editor, check it in the live preview, and share the resulting https://<token>.cognition.run link with your participants. Each trial is uploaded as soon as it finishes; if a participant loses their connection, a service worker keeps the trials locally and resends them when the connection returns, and everything is flushed before your on_finish runs. The CSV or JSON export includes the string, word, response, rt and correct columns used above.
If your design has between-subjects conditions (for example, different prime lists), Cognition balances assignment on the server and exposes the condition number as window.CONDITION. Participant IDs from Prolific or SONA passed in the URL are added to every trial automatically; see our integration guide for completion codes and redirects. Create a free account to host up to 4 tasks with 60 participants each, or read the documentation.
The demo above was created using the jsPsych library—a powerful tool for building behavioral experiments in a web browser. This library provides a flexible framework for designing a wide variety of cognitive tests, making it a favorite among researchers and educators.
What's even more exciting is that this demo is hosted using Cognition. Cognition offers a seamless platform to create, run, and manage online experiments, relieving users of the complexities related to web hosting, data storage, and security.
Inspired by what you've seen? Ready to dive into the world of online experiments? With Cognition, you can run and share your experiments online effortlessly. Whether you're a seasoned researcher or just curious about cognitive tests, Cognition is here to simplify the journey.