Why have jsPsych methods suddenly stopped working on my computer? #2329
-
Hello all! While working on an experiment, I suddenly found that the jsPsych.randomization.shuffle() method would not work properly. I tried to execute the following code:
When I execute the console.log function, I receive an empty array in return (i.e., the newArray function failed). I am unsure why that is happening. All of the necessary plugin scripts have been loaded into the experiment, so I suspect that the problem stems from a syntax error. However, the code looks fine to me (though I am an inexperienced coder). Would someone please tell me why my code is not working? For reference, I am using jsPsych version 6.3.1. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @woodenchair, the issue here is that the You can move the var newArray = function() {
numbers_randomized = jsPsych.randomization.shuffle(numbers);
console.log(numbers_randomized);
return numbers_randomized;
}; You can also try calling the var numbers = [1, 2, 3, 4, 5];
var numbers_randomized = [];
var newArray = function() {
numbers_randomized = jsPsych.randomization.shuffle(numbers);
return numbers_randomized;
};
newArray();
console.log(numbers_randomized) |
Beta Was this translation helpful? Give feedback.
Hi @woodenchair, the issue here is that the
call-function
plugin doesn't run thefunc
function until after the experiment starts, when jsPsych reaches thetest
trial in your experiment timeline. But yourconsole.log
is in your main script so it's running before the function is called (when the page loads, before the experiment starts).You can move the
console.log
into thenewArray
function to see when the function is called and to check that the randomization is working:You can also try calling the
newArray
function before thecons…