Reputation: 163
I am a beginner in JsPsych and new to JS as well. I am having some difficulty with using the JsPsych.timelineVariable()
. Just to get myself oriented with the program, I am trying to code a simple math quiz. I made an object of math questions, and used the documentation on jsPsych to reference the object as the prompt for my survey text variable. But, when I open the html file, I see 'undefined' in place of the prompt. If I replace the prompt command with a string, it works fine, so I know I am doing something wrong with the timelineVariable()
. I tried it in two different ways, with the first way commented out:
<!DOCTYPE html>
<html>
<head> <!-- all preloads go into head -->
<title>Math Quiz</title>
<!-- any plugins go here-->
<script src="jspsych/dist/jspsych.js"></script>
<script src = "jspsych/dist/plugin-survey-text.js"></script>
<link href="jspsych/dist/jspsych.css" rel="stylesheet" type="text/css" />
</head>
<body> <!-- all script for tasks go into body-->
<script>
var jsPsych = initJsPsych();
/*
var timeline = [];
var mathQuestions = [
{math: '2+2 = ?', correct: '4'},
{math: '2x3 = ?', correct: '6'},
{math: '5x7 = ?', correct: '35'}
];
var test = {
type: jsPsychSurveyText,
questions: [
{prompt: jsPsych.timelineVariable('math'),
name: 'resp'}
]
};
*/
var test = {
timeline: [
{
type: jsPsychSurveyText,
stimulus: jsPsych.timelineVariable('math')
}
],
timeline_variables: [
{ math: '2+2'},
{ math: '3+5'},
{ math: '10+7'}
]
}
jsPsych.run([test]);
</script>
</body>
</html>
Thank you for your help!
Upvotes: 1
Views: 313
Reputation: 2380
You've got bits of the right idea in both of the examples, but they need to be combined together. The first code chunk doesn't work because the test
trial is not on a timeline with timeline variables attached. The second chunk doesn't work because the SurveyText plugin doesn't have a stimulus
parameter.
I think this should work:
var timeline = [];
var mathQuestions = [
{math: '2+2 = ?', correct: '4'},
{math: '2x3 = ?', correct: '6'},
{math: '5x7 = ?', correct: '35'}
];
var test = {
type: jsPsychSurveyText,
questions: [
{
prompt: jsPsych.timelineVariable('math'),
name: 'resp'
}
]
};
var mathQuestionProcedure = {
timeline: [test],
timeline_variables: mathQuestions
}
timeline.push(mathQuestionProcedure)
Upvotes: 2