我使用一个for循环来创建测试试验,其中每个测试项只显示一次,但是最后一个项目总是出现的,twice.The循环意味着以随机顺序显示每个岩石大小一次。我已经尝试过各种随机化功能(洗牌、shuffleNoRepeats、sampleWithoutReplacement、重复),但它们都没有发挥作用。我继承了这段代码,并且正在修改它,而不是自己编写整个代码。我还注意到,数据参数并不记录显示的项目的实际大小,而是按升序记录它们。
也许这个循环有一个问题,但我还不能确定是什么问题,所以如果有人能看一看,看看他们是否能发现出了什么问题,我会非常感激。
这是我的代码:
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) 我怎么才能停止重复最后的审判?
发布于 2022-11-23 13:18:22
删除最后一个timeline.push(rate),以摆脱显示两次的最后一次试用。
另外,这里有一个稍微健壮一些的代码版本,只需进行最小的更改。请注意,我只是在使用rocksize数组创建试验之前对其进行洗牌(试验次数N_TRIALS等于rocksize的数组长度)。
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="jspsych.js"></script>
<script src="jspsych-html-button-response.js"></script>
<script src="jspsych-html-keyboard-response.js"></script>
<link href="jspsych.css" rel="stylesheet" type="text/css" />
</head>
<body></body>
<script>
var timeline = [];
var rocksize = jsPsych.randomization.shuffle([24, 34, 43, 53, 62, 71, 90]);
const N_TRIALS = rocksize.length
for (var trial_ind = 0; trial_ind < N_TRIALS; trial_ind++) {
var rate = {
type: "html-button-response",
timing_post_trial: 500,
stimulus: 'rock size: ' + rocksize[trial_ind],
choices: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
prompt: "MY PROMPT",
data: {
trial: trial_ind,
rocksize: rocksize[trial_ind]
}
}
timeline.push(rate)
var wait = {
type: "html-keyboard-response",
stimulus: " ",
choices: jsPsych.NO_KEYS,
trial_duration: 1000,
}
timeline.push(wait)
}
// timeline.push(rate) -- remove this to get yours to work
jsPsych.init({timeline: timeline})
</script>
</html>请注意,我使用了jsPsych v6.3.1,因为您似乎使用了7.0之前的版本。
https://stackoverflow.com/questions/61035799
复制相似问题