Below is the code for my inspection time task that I am developing for my thesis. I am new to coding but I have put a great deal of effort into this and cannot seem to figure out why "accuracy" continues to return as false for these trials. Please let me know where I am going wrong.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>mental_speed</title>
<script src="
https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="jspsych/jspsych.js"></script>
<script src="jspsych/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych/plugins/jspsych-image-keyboard-response.js"></script>
<script src="jspsych/plugins/jspsych-instructions.js"></script>
<script src="
https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<link href="jspsych/css/jspsych.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="
https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
</head>
<body>
<script>
var timeline = [];
var welcome = {
type: 'html-keyboard-response',
stimulus: "Welcome to our experiment. Press enter to continue.",
choices: ['Enter']
};
timeline.push(welcome);
var Detect_Ident = {
timeline: [
{
type: 'html-keyboard-response',
stimulus: '<p> Ready </p>',
prompt: "Press 'Enter' to begin trial.",
choices: ['Enter']
},
{
type: 'image-keyboard-response',
stimulus: 'images/blank.png',
choices: jsPsych.NO_KEYS,
trial_duration: 500
},
{
type: 'html-keyboard-response',
stimulus: '#',
choices: jsPsych.NO_KEYS,
trial_duration: 30
},
{
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus'),
choices: jsPsych.NO_KEYS,
trial_duration: jsPsych.timelineVariable('trial_duration')
},
{
type: 'html-keyboard-response',
stimulus: '#',
choices: jsPsych.NO_KEYS,
trial_duration: 300
},
{
type: 'html-keyboard-response',
stimulus: "<p> Was a letter displayed? Press 'y' for yes and 'n' for no.",
choices: ['y', 'n'],
data: {
task: jsPsych.timelineVariable('condition'),
correct_response: jsPsych.timelineVariable('correct_response_1')
},
on_finish: function(data){
var accuracy = false;
if (data.correct_response == jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press)){
accuracy = true;
}
data.accuracy = accuracy;
}
},
{
type: 'html-keyboard-response',
stimulus: "Press 'R', 'B', 'P' for the letter that was presented. If no letter was presented press 'X'",
choices: ['r', 'b', 'p', 'x'],
data: {
task: jsPsych.timelineVariable('condition'),
correct_response: jsPsych.timelineVariable('correct_response_2')
},
on_finish: function(data){
var accuracy = false;
if (data.correct_response == jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press)){
accuracy = true;
}
data.accuracy = accuracy;
},
],
};
var trial_info = [
{stimulus: 'R', condition: 'R_80', trial_duration: 80, correct_response_1: 'Y', correct_response_2: 'R'},
{stimulus: 'R', condition: 'R_50', trial_duration: 50, correct_response_1: 'Y', correct_response_2: 'R'},
{stimulus: 'R', condition: 'R_30', trial_duration: 30, correct_response_1: 'Y', correct_response_2: 'R'},
{stimulus: 'R', condition: 'R_20', trial_duration: 20, correct_response_1: 'Y', correct_response_2: 'R'},
{stimulus: 'R', condition: 'R_16', trial_duration: 16, correct_response_1: 'Y', correct_response_2: 'R'},
{stimulus: 'B', condition: 'B_80', trial_duration: 80, correct_response_1: 'Y', correct_response_2: 'B'},
{stimulus: 'B', condition: 'B_50', trial_duration: 50, correct_response_1: 'Y', correct_response_2: 'B'},
{stimulus: 'B', condition: 'B_30', trial_duration: 30, correct_response_1: 'Y', correct_response_2: 'B'},
{stimulus: 'B', condition: 'B_20', trial_duration: 20, correct_response_1: 'Y', correct_response_2: 'B'},
{stimulus: 'B', condition: 'B_16', trial_duration: 16, correct_response_1: 'Y', correct_response_2: 'B'},
{stimulus: 'P', condition: 'P_80', trial_duration: 80, correct_response_1: 'Y', correct_response_2: 'P'},
{stimulus: 'P', condition: 'P_50', trial_duration: 50, correct_response_1: 'Y', correct_response_2: 'P'},
{stimulus: 'P', condition: 'P_30', trial_duration: 30, correct_response_1: 'Y', correct_response_2: 'P'},
{stimulus: 'P', condition: 'P_20', trial_duration: 20, correct_response_1: 'Y', correct_response_2: 'P'},
{stimulus: 'P', condition: 'P_16', trial_duration: 16, correct_response_1: 'Y', correct_response_2: 'P'}
];
var trial_procedure = {
timeline: [Detect_Ident],
timeline_variables: trial_info
};
timeline.push(trial_procedure)
jsPsych.init({
timeline: timeline,
case_sensitive: false,
on_finish: function(){
jsPsych.data.displayData('csv');
}
});
</script>
</body>
</html>