Conditionally adding a value to an array based on previous trial data #2494
-
Hi there! I've been working on a task for a few months now and I'm at the stage where I want to run it on Prolific, but I'm having trouble getting one last part to work. The task is a betting game, and I'm trying to award participants money based on their performance (and eventually display a screen at the end that says "you won x $"). There are four categories of images, and I'm trying to write a code that adds 0.05 to a pre-defined array of "money" based on whether they identified the image correctly. The names of the images are strings and I want to compare a subset of the strings (whether the string contains "ff", "fs", "ss", or "sf") to the response provided by the participant (either 0 or 1). I have three questions: (1) Since I have written and added Any advice at all would be greatly appreciated. Here is a relevant section of my code:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @mcd710, for (1), you're getting the error because you can't put a function on the timeline - everything in the timeline array should be an object. To run your For (3), I don't think what you have is quite right so I've suggested something else below. But I haven't tested this so it might not work. So to check, I've added statements to print out the values to the browser's JavaScript console. var image_data_ff_fs = jsPsych.data.getLastTimelineData().select('stimulus').subset(function(x){
console.log('stimulus: ', x);
console.log('includes ff or fs: ', x.includes('ff') || x.includes('fs'));
return x.includes('ff') || x.includes('fs');
});
console.log('image data ff fs: ', image_data_ff_fs); I hope this helps! Can you let us know if these solutions work for you? |
Beta Was this translation helpful? Give feedback.
Hi @mcd710, for (1), you're getting the error because you can't put a function on the timeline - everything in the timeline array should be an object. To run your
countFunction
at that point in the timeline, you can either call the function (a) from inside the conditional function in yourif_node
(after your existing code but before the return statements), or (b) using thecall-function
plugin. That should answer (2) as well.For (3), I don't think what you have is quite right so I've suggested something else below. But I haven't tested this so it might not work. So to check, I've added statements to print out the values to the browser's JavaScript console.