accuracy continues to return as "false" on every trial. please help #1740
-
I have tried and tried to figure out what is going on but I cannot understand why my the accuracy continues to return as false. The code is below for an inspection time task that I have been working on. Please let me know what I can do <!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> |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 2 replies
-
Hi @johnsonjm4. What version of jsPsych are you using? |
Beta Was this translation helpful? Give feedback.
-
6.3
…On Mon, Apr 19, 2021 at 9:13 AM Josh de Leeuw ***@***.***> wrote:
Hi @johnsonjm4 <https://github.com/johnsonjm4>. What version of jsPsych
are you using?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1740 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF2EUGBFAJKY27XWK6OX4RDTJQ3A3ANCNFSM43F4Y42Q>
.
|
Beta Was this translation helpful? Give feedback.
-
I believe it is 6.3 I will run it again to make sure
On Mon, Apr 19, 2021 at 9:22 AM John Mark Johnson ***@***.***>
wrote:
… 6.3
On Mon, Apr 19, 2021 at 9:13 AM Josh de Leeuw ***@***.***>
wrote:
> Hi @johnsonjm4 <https://github.com/johnsonjm4>. What version of jsPsych
> are you using?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#1740 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AF2EUGBFAJKY27XWK6OX4RDTJQ3A3ANCNFSM43F4Y42Q>
> .
>
|
Beta Was this translation helpful? Give feedback.
-
Yes it is 6.3
On Mon, Apr 19, 2021 at 9:22 AM John Mark Johnson ***@***.***>
wrote:
… I believe it is 6.3 I will run it again to make sure
On Mon, Apr 19, 2021 at 9:22 AM John Mark Johnson ***@***.***>
wrote:
> 6.3
>
> On Mon, Apr 19, 2021 at 9:13 AM Josh de Leeuw ***@***.***>
> wrote:
>
>> Hi @johnsonjm4 <https://github.com/johnsonjm4>. What version of jsPsych
>> are you using?
>>
>> —
>> You are receiving this because you were mentioned.
>> Reply to this email directly, view it on GitHub
>> <#1740 (comment)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AF2EUGBFAJKY27XWK6OX4RDTJQ3A3ANCNFSM43F4Y42Q>
>> .
>>
>
|
Beta Was this translation helpful? Give feedback.
-
In version 6.3 we made a few changes that affect this code:
With those changes, your on_finish: function(data){
data.accuracy = jsPsych.pluginAPI.compareKeys(data.correct_response, data.response)
} |
Beta Was this translation helpful? Give feedback.
-
Oh thank God!!! I have been driving myself mad. Thank you so much for the
assistance.
…On Mon, Apr 19, 2021 at 9:41 AM Josh de Leeuw ***@***.***> wrote:
In version 6.3 we made a few changes that affect this code:
1. We standardized the name of the variable containing the user's
response on a trial to response. So instead of data.key_press you'll
use data.response.
2. We dropped support for numeric key codes, which are now considered
deprecated by web browsers. data.response will be a character string.
We recommend using the function jsPsych.pluginAPI.compareKeys(key1,
key2) to determine if two values match.
With those changes, your on_finish function should look like this:
on_finish: function(data){
data.accuracy = jsPsych.pluginAPI.compareKeys(data.correct_response, data.response)}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1740 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF2EUGECHE7YVSNP7CK6WIDTJQ6KZANCNFSM43F4Y42Q>
.
|
Beta Was this translation helpful? Give feedback.
-
One last quick question..
Is there a way to have a blank trial using the html-keyboard-response?
I.e. to have a stimulus where nothing is displayed?
On Mon, Apr 19, 2021 at 9:53 AM John Mark Johnson ***@***.***>
wrote:
… Oh thank God!!! I have been driving myself mad. Thank you so much for the
assistance.
On Mon, Apr 19, 2021 at 9:41 AM Josh de Leeuw ***@***.***>
wrote:
> In version 6.3 we made a few changes that affect this code:
>
> 1. We standardized the name of the variable containing the user's
> response on a trial to response. So instead of data.key_press you'll
> use data.response.
> 2. We dropped support for numeric key codes, which are now considered
> deprecated by web browsers. data.response will be a character string.
> We recommend using the function jsPsych.pluginAPI.compareKeys(key1,
> key2) to determine if two values match.
>
> With those changes, your on_finish function should look like this:
>
> on_finish: function(data){
> data.accuracy = jsPsych.pluginAPI.compareKeys(data.correct_response, data.response)}
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#1740 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AF2EUGECHE7YVSNP7CK6WIDTJQ6KZANCNFSM43F4Y42Q>
> .
>
|
Beta Was this translation helpful? Give feedback.
-
Last thing, I am having problems creating a debrief block. Below is the
code. I keep getting ${overall_acc} returned with no value for overall_acc.
Any ideas?
var debrief_block = {
type: 'html-keyboard-response',
stimulus: function() {
var trials = jsPsych.data.get().filter({task: 'questions'}).count;
var correct_trials = jsPsych.data.get().filter({accuracy: true}).count;
var overall_acc = Math.round(correct_trials / trials * 100);
return '<p> You responded correctly on ${overall_acc} % of the trials.
</p>';
}
};
…On Mon, Apr 19, 2021 at 10:28 AM Josh de Leeuw ***@***.***> wrote:
Sure, just use an empty string: stimulus: "".
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1740 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF2EUGASAO3IBHBLINPKSQ3TJRDYRANCNFSM43F4Y42Q>
.
|
Beta Was this translation helpful? Give feedback.
-
Yes thank you so much. That was such a stupid mistake on my part
…On Wed, Apr 21, 2021 at 4:06 PM Becky Gilbert ***@***.***> wrote:
To use template literals/strings in JavaScript, I think you need to use
backticks rather than single quotes. See docs here
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals>
.
Try this:
return `<p> You responded correctly on ${overall_acc} % of the trials.</p>`;
Does that work?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1740 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF2EUGB36LKNFPIKUZCXWT3TJ4455ANCNFSM43F4Y42Q>
.
|
Beta Was this translation helpful? Give feedback.
In version 6.3 we made a few changes that affect this code:
response
. So instead ofdata.key_press
you'll usedata.response
.data.response
will be a character string. We recommend using the functionjsPsych.pluginAPI.compareKeys(key1, key2)
to determine if two values match.With those changes, your
on_finish
function should look like this: