Selecting a difficulty level based on the users response. HTML Button Response #3268
-
Hey everyone! This is my first time designing and experiment, so thanks in advance for the patience and understanding. I'm trying to do so using cognition.run and the jspsych library 7.3. I want to design a task that asks the user whether they wish to modify the difficulty level on a set of questions. However, what i have so far doesn't pick up on the user's response and doesn't modify the difficulty level. This experiment is for my thesis and I want to finish it ASAP but I've been stuck on this problem for a month now. This is my code for this part of the experiment. var timeline = []; function sumMax5 (a) { // Functions allow to add or substract a level of difficulty without passing the range of 1 through 5 function diffMin1 (a) { for(var i = 0; i < 3; i++){ timeline.push({ jsPsych.run(timeline); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
You have made exactly the same mistakes new learners of jsPsych commonly make (not a mockery, just my personal opinion that the official documentation never laid enough stress on the matter). I have been teaching my fellow students on jsPsych, and whenever I do, I would tell them this: creating a trial in jsPsych does not mean that it is run upon creation, and running a trial in jsPsych does not mean the parameters are being evaluated when the trial is run. So how have you been mistaken? You are pushing the trials into the timeline with a loop, and you wrote down these lines: timeline.push(difficultySelection);
if (chosenDifficulty == 0) {//Button tag for 'Easier' is 0
difficultyLevel = diffMin1(difficultyLevel);
} else if (chosenDifficulty == 2) { //Button tag for 'Harder' is 2
difficultyLevel = sumMax5(difficultyLevel);
} No doubt you want to adjust the difficulty level after a difficulty-selection trial. However, take a look at the first half of my saying:
The trial is created, but it is not run until var difficultySelection = {
type: jsPsychHtmlButtonResponse,
stimulus: 'Do you wish to modify the difficulty?',
choices: ['Easier', 'Same', 'Harder'],
prompt: '',
required: true,
button_html: '%choice%',
on_finish: function (data) {
chosenDifficulty = data.response;
if (chosenDifficulty == 0) {
//Button tag for 'Easier' is 0
difficultyLevel = diffMin1(difficultyLevel);
} else if (chosenDifficulty == 2) {
//Button tag for 'Harder' is 2
difficultyLevel = sumMax5(difficultyLevel);
}
},
}; I see you have already used an Now, back away from
You have this in your loop: timeline.push({
type: jsPsychHtmlKeyboardResponse,
stimulus: "The current level of difficulty is: " + difficultyLevel + ".",
choices: "NO_KEYS",
trial_duration: 1500
}); You must have intended the trial to show the chosen difficulty level using the value modified by the user. However, the parameters of a trial is calculated when the trial object is defined, not when the experiment starts to run. And there you have it, you have created three trials which all show the initial timeline.push({
type: jsPsychHtmlKeyboardResponse,
stimulus: () => 'The current level of difficulty is: ' + difficultyLevel + '.',
choices: 'NO_KEYS',
trial_duration: 1500,
}); See how I use an arrow function instead to return the value. The complete code: var jsPsych = initJsPsych({
on_finish: function () {
jsPsych.data.displayData();
},
});
var timeline = [];
//var dificultadActual = 3;
var chosenDifficulty = 1;
var difficultyLevel = 3;
function sumMax5(a) {
// Functions allow to add or substract a level of difficulty without passing the range of 1 through 5
var result = a;
result++;
if (result > 5) {
result = 5;
}
return result;
}
function diffMin1(a) {
var result = a;
result--;
if (result < 1) {
result = 1;
}
return result;
}
var difficultySelection = {
type: jsPsychHtmlButtonResponse,
stimulus: 'Do you wish to modify the difficulty?',
choices: ['Easier', 'Same', 'Harder'],
prompt: '',
required: true,
button_html: '%choice%',
on_finish: function (data) {
chosenDifficulty = data.response;
if (chosenDifficulty == 0) {
//Button tag for 'Easier' is 0
difficultyLevel = diffMin1(difficultyLevel);
} else if (chosenDifficulty == 2) {
//Button tag for 'Harder' is 2
difficultyLevel = sumMax5(difficultyLevel);
}
},
};
for (var i = 0; i < 3; i++) {
timeline.push(difficultySelection);
timeline.push({
type: jsPsychHtmlKeyboardResponse,
stimulus: () => 'The current level of difficulty is: ' + difficultyLevel + '.',
choices: 'NO_KEYS',
trial_duration: 1500,
});
}
jsPsych.run(timeline); |
Beta Was this translation helpful? Give feedback.
You have made exactly the same mistakes new learners of jsPsych commonly make (not a mockery, just my personal opinion that the official documentation never laid enough stress on the matter).
I have been teaching my fellow students on jsPsych, and whenever I do, I would tell them this: creating a trial in jsPsych does not mean that it is run upon creation, and running a trial in jsPsych does not mean the parameters are being evaluated when the trial is run. So how have you been mistaken?
You are pushing the trials into the timeline with a loop, and you wrote down these lines: