I'm using a for loop to create test trials in which each test item is presented once but the final item is always presented twice.The loop is meant to show each rocksize once in a random order. I've tried various randomisation functions (shuffle, shuffleNoRepeats, sampleWithoutReplacement, repeat) but none of them does the job. I inherited this code and am adapting it rather than writing the whole thing myself. I also noticed the data arguments don't record the actual sizes of the items presented but records them in ascending order.
Perhaps there's an issue with the loop but I haven't been able to identify what the problem is, so would be really grateful if someone could have a look and see whether they can spot what's wrong.
Here is my code:
var rocksize = [24, 34, 43, 53, 62, 71, 90];
var rateqorder = jsPsych.randomization.repeat([0, 1, 2, 3, 4, 5, 6], 1);
// var rateqorder = jsPsych.randomization.shuffleNoRepeats([0, 1, 2, 3, 4, 5, 6]); // A few different things I've tried
console.log(rocksize)
console.log(rateqorder)
for (var i = 0; i < rateqorder.length; i++) {
var rate = {
type: "html-button-response",
timing_post_trial: 500,
stimulus:
'<div class="ratecontainer">' +
'<div class="head"></div>' +
'<div class="head"></div>' +
'<div class="head"></div>' +
'<div class="mid"></div>' +
'<div class="center">' +
'<div class="raterock">' +
'<span class="ratedot" style="height:' + rocksize[rateqorder[i]] + 'px; width:' + rocksize[rateqorder[i]] + 'px;"></span>' +
'</div></div>' +
'<div class="mid"></div>' +
'<div class="foot"></div>' +
'<div class="foot"></div>' +
'<div class="foot"></div>' +
'</div>' +
'<span><p>Based on what you have learned so far, how likely is it that a Sodor sphere of this size has plaxium coating?<br><br><br></p></span>',
choices: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
prompt: "<span style='font-size:15px'>[Very Unlikely]" + " " +
"[Very Likely]</span>",
data: {
trial: rateqorder[i],
rocksize: rocksize[i]
}
}
timeline.push(rate)
var wait = {
type: "html-keyboard-response",
stimulus: " ",
choices: jsPsych.NO_KEYS,
trial_duration: 1000,
}
timeline.push(wait)
}
timeline.push(rate)
How can I stop it repeating the final trial?
Remove the last
timeline.push(rate)
to get rid of the last trial showing twice.Also, here's a slightly more robust version of your code with minimal changes. Notice how I only shuffle the
rocksize
's array before creating trials with them (with number of trialsN_TRIALS
equal to therocksize
's array length)Note that I have used jsPsych v6.3.1 as it seems you have used version before 7.0.