Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Debugging


This is my script to pseudorandomize the trials:


function getPseudoRandomizedTrials(data) {

let trials = [...data], randomizedTrials = [], lastWord = null;


while (trials.length) {


// Filtere Trials, die das gleiche Wort wie lastWord haben

let choices = trials.filter(t => t.exp_word !== lastWord);


// Wenn keine gültigen Optionen übrig sind, wähle zufällig einen aus allen verbleibenden Trials

if (choices.length === 0) {

choices = [...trials];

}


// Wähle zufällig ein Trial aus den Choices

let chosen = choices[Math.floor(Math.random() * choices.length)];

randomizedTrials.push(chosen);


// Setze lastWord auf das exp_word des gewählten Trials

lastWord = chosen.exp_word;


// Überprüfen, ob der aktuelle Stimulus gleich dem letzten ist


if (lastWord !== null && lastWord === chosen.exp_word) {

vars.rep = 1;

} else {

vars.rep = 0;

}


// Entferne das gewählte Trial aus der Liste

trials.splice(trials.indexOf(chosen), 1);

}

}


And now, I want to be sure that the Script is used and the trials are chosen in consequence of the script. Therefore i want to create a new variable that indicates in debugging that the randomization was successful.

Maybe:

vars.rand_word = chosen.exp_word ?

Sign In or Register to comment.