求教用js搭建web实验
请大神教javascript! 我要学一些很简单的js搭建的心理学实验,我已经有模板code了,给我解释一下各行code的用法就好了。本人坐标美国,文科在读博士,刚在codecademy上自学了一点html/css和js的基础,还有很多不懂!可以email或者google hangout,skype进行教学。可以付费,我也可以帮改英语作业英语论文或者美国申请资料等。拜托拜托各位高手!导师要我暑假就要学起来了,零基础自学鸭梨山大~~我的邮箱是xushan14@。
导师给我的html code 如下:(没错难度就是这么低我都不懂:( )
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Multitasking</title>
<script src="http://ajax. is a library of function code -->
<script src="scripts/jspsych.js"></script> <!--specifies the URL of an external script file.-->
<script src="scripts/plugins/jspsych-text.js"></script><!--??-->
<script src="mtfood v6.js" type="text/javascript"></script><!--why link four files?-->
<link href="experiment.css" type="text/css" rel="stylesheet"></link>
<!-- Load the jspsych library and plugins -->
</head>
<body>
<div id="jspsych_target"></div>
</body>
<script type="text/javascript">
// best to store the randomized images in this section and then feed into jspsych
// ************************* IMG trial ******************************************
var junk_src = "Junk Food Items/"; //from here is js code? this is an an external script file?
var health_src = "Health Food Items/";//this we can put words before src e.g. health_src =
var health_img = [health_src+"h1-fruitSalad-ok.jpg",
health_src+"h2-yogurtMuesli-ok.jpg",
health_src+"h3-citrusCup-ok.jpg",
health_src+"h4-applechips-ok.jpg",
health_src+"h5-oatmeal-ok.jpg"];
var junk_img = [junk_src+"j1-applePie-ok.jpg",
junk_src+"j2-iceCream-ok.jpg",
junk_src+"j3-citrusCake-ok.jpg",
junk_src+"j4-potatoChips-ok.jpg",
junk_src+"j5-waffles-ok.jpg"];
function randomize_stimuli(array1,array2){// function to randomize stimuli
var matrix = [];//?
var x = 0;//?
var n=0;//?
for(var i=0; i<array1.length; i++) {// create matrix to store the stimuli for each condition
for(var j=0; j<array2.length; j++){
matrix[n] = new Array(2);//?
x = Math.floor((Math.random() * 2)+1);//random number between 1 and 2 to determine left or right presentation of img, math.floor means round a number downward to its nearest integer
if(x==1){
matrix[n][0] = array1[i];//?
matrix[n][1] = array2[j];//?
}
else if(x==2){
matrix[n][1] = array1[i];//?
matrix[n][0] = array2[j];//?
}
n=n+1;//?
}
}
//shuffle stimuli ****what is this for???
var m = matrix.length, t, tt, d;//???
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
d = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = matrix[m][0]; //?
tt = matrix[m][1];//?
matrix[m][0] = matrix[d][0]; //?
matrix[m][1] = matrix[d][1]; //?
matrix[d][0]= t; //?
matrix[d][1]= tt; //?
}
return matrix;
} //?the set of codes?
var img = randomize_stimuli(health_img,junk_img);
var debrief = "<div id='instructions'><p>Thank you for " +
"participating! Press enter to see the data.</p></div>";
var cent_block = { //?
type: "mtfood",//?
stim: img //?
};//?
var debrief_block = {
type: "text",
text: [debrief]
};
// an array of paths to images that need to be loaded
jsPsych.preloadImages(img, function(){ startExperiment(); });
function startExperiment(){
jsPsych.init({
display_element: $('#jspsych_target'),
experiment_structure: [cent_block,debrief_block],
on_finish: function(data) {
$("#jspsych_target").append($('<pre>', {
html: jsPsych.dataAsCSV()
}));
jsPsych.saveCSVdata("data.csv");
}
});
}
</script>
</html>
--