/** * jspsych-cloze * Philipp Sprengholz * * Plugin for displaying a cloze test and checking participants answers against a correct solution. * * documentation: docs.jspsych.org **/ jsPsych.plugins['cloze'] = (function () { var plugin = {}; plugin.info = { name: 'cloze', description: '', parameters: { text: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Cloze text', default: undefined, description: 'The cloze text to be displayed. Blanks are indicated by %% signs and automatically replaced by input fields. If there is a correct answer you want the system to check against, it must be typed between the two percentage signs (i.e. %solution%).' }, button_text: { type: jsPsych.plugins.parameterType.STRING, pretty_name: 'Button text', default: 'OK', description: 'Text of the button participants have to press for finishing the cloze test.' }, check_answers: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'Check answers', default: false, description: 'Boolean value indicating if the answers given by participants should be compared against a correct solution given in the text (between % signs) after the button was clicked.' }, mistake_fn: { type: jsPsych.plugins.parameterType.FUNCTION, pretty_name: 'Mistake function', default: function () {}, description: 'Function called if check_answers is set to TRUE and there is a difference between the participants answers and the correct solution provided in the text.' } } }; plugin.trial = function (display_element, trial) { var html = '
'; var elements = trial.text.split('%'); var solutions = []; for (var i=0; i'; } } html += '
'; display_element.innerHTML = html; var check = function() { var answers = []; var answers_correct = true; for (var i=0; i'; display_element.querySelector('#finish_cloze_button').addEventListener('click', check); }; return plugin; })();