Skip to content

Instantly share code, notes, and snippets.

@davetannenbaum
Last active August 29, 2015 14:15
Show Gist options
  • Save davetannenbaum/e3ce363314c08fbf8a0a to your computer and use it in GitHub Desktop.
Save davetannenbaum/e3ce363314c08fbf8a0a to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>My experiment</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="jsPsych-4.0.1/jspsych.js"></script>
<script src="jsPsych-4.0.1/plugins/jspsych-text.js"></script>
<script src="jsPsych-4.0.1/plugins/jspsych-survey-text.js"></script>
<script src="jsPsych-4.0.1/plugins/underscore.js"></script>
<link href="jsPsych-4.0.1/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body>
</body>
<script>
// welcome block
var block1 = {
type: "text",
text: "Welcome. In this study you will provide estimates for three upcoming NBA basketball games."
};
// setting up counterbalancing of focal team for each trial
var game1 = _.sample([ {focal: " Chicago Bulls ", foil: " Detroit Pistons "},
{focal: " Detroit Pistons ", foil: " Chicago Bulls "}], 1);
var game2 = _.sample([ {focal: " Toronto Raptors ", foil: " Charlotte Hornets "},
{focal: " Charlotte Hornets ", foil: " Toronto Raptors "}], 1);
var game3 = _.sample([ {focal: " Memphis Grizzlies ", foil: " LA Clippers "},
{focal: " LA Clippers ", foil: " Memphis Grizzlies "}], 1);
// epistemic trials
var e1 = ["The" + _.pluck(game1, "focal") + "will play the" + _.pluck(game1, "foil") + "on March 21st.</p>" +
"<p>What is the probability that the" + _.pluck(game1, "focal") + "will win?"];
var e2 = ["The" + _.pluck(game2, "focal") + "will play the" + _.pluck(game2, "foil") + "on March 6th.</p>" +
"<p>What is the probability that the" + _.pluck(game2, "focal") + "will win?"];
var e3 = ["The" + _.pluck(game3, "focal") + "will play the" + _.pluck(game3, "foil") + "on February 23rd.</p>" +
"<p>What is the probability that the" + _.pluck(game3, "focal") + "will win?"];
var e_block = {
type: 'survey-text',
questions: _.shuffle([e1, e2, e3]),
};
// aleatory trials
var a1 = ["The" + _.pluck(game1, "focal") + "will play the" + _.pluck(game1, "foil") + "on February 20th, March 21st, and April 3rd.</p>" +
"<p>What is the probability that the" + _.pluck(game1, "focal") + "win on March 21st?"];
var a2 = ["The" + _.pluck(game2, "focal") + "will play the" + _.pluck(game2, "foil") + "on March 6th, April 8th, and April 15th.</p>" +
"<p>What is the probability that the" + _.pluck(game2, "focal") + "will win on March 6th?"];
var a3 = ["The" + _.pluck(game3, "focal") + "will play the" + _.pluck(game3, "foil") + "on February 23rd, February 27th, and April 11th.</p>" +
"<p>What is the probability that the" + _.pluck(game3, "focal") + "win on February 23rd?"];
var a_block = {
type: 'survey-text',
questions: _.shuffle([a1, a2, a3]),
};
// random assignment to epistemic or aleatory condition
var bball_games = [e_block, a_block];
var block2 = _.sample(bball_games,1)[0];
// building the experiment
var experiment = _.union([block1, block2]);
jsPsych.init({
experiment_structure: experiment
});
</script>
</html>
@paultannenbaum
Copy link

Here's my feedback

  • Name the gist demo_experiment.html and you will get color formatting
  • var block2 = bball_games[_.sample([0,1],1)]; would probably be better written as var block2 = _.sample(bball_games,1)[0]; as it is more descriptive of the result you are trying to achieve.
  • The part where you push the experiments into the array can also be done a bit more terse like this var experiment = _.union([block1], block2)

Overall it looks fine though. There are some project structure things you would want to change if this was gonna grow in size, but for now its fine. Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment