From 10ca06ce14b3b982fb45e1660010b3e7db2a09a9 Mon Sep 17 00:00:00 2001 From: jadeddelta <101148768+jadeddelta@users.noreply.github.com> Date: Thu, 20 Oct 2022 00:11:38 -0400 Subject: [PATCH] added multiple answer checking --- examples/jspsych-cloze.html | 4 ++-- packages/plugin-cloze/src/index.spec.ts | 1 + packages/plugin-cloze/src/index.ts | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/jspsych-cloze.html b/examples/jspsych-cloze.html index aebc1982..ef8d67fa 100644 --- a/examples/jspsych-cloze.html +++ b/examples/jspsych-cloze.html @@ -22,10 +22,10 @@ text: 'The %% is the largest terrestrial mammal. It lives in both %% and %%.' }); - // an example that allows the user to input a solution that doesn't require case sensitivity + // an example that allows the user to input a solution that doesn't require case sensitivity, and allows multiple responses timeline.push({ type: jsPsychCloze, - text: 'The %CASE% is closed.', + text: 'The %CASE/door/EyE% is closed.', check_answers: true, case_sensitivity: false, }) diff --git a/packages/plugin-cloze/src/index.spec.ts b/packages/plugin-cloze/src/index.spec.ts index 30307fc5..38c4eca6 100644 --- a/packages/plugin-cloze/src/index.spec.ts +++ b/packages/plugin-cloze/src/index.spec.ts @@ -218,6 +218,7 @@ describe("cloze", () => { }); describe("cloze simulation", () => { + //TODO: bro why is this not working (wraps this in array but not the next one) test("data-only mode works", async () => { const { getData, expectFinished } = await simulateTimeline([ { diff --git a/packages/plugin-cloze/src/index.ts b/packages/plugin-cloze/src/index.ts index 9ad952a0..46be9869 100644 --- a/packages/plugin-cloze/src/index.ts +++ b/packages/plugin-cloze/src/index.ts @@ -3,7 +3,7 @@ import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych"; const info = { name: "cloze", parameters: { - /** 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%). */ + /** 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%). For multiple answers, type them with a slash (i.e. %1/2/3%). */ text: { type: ParameterType.HTML_STRING, pretty_name: "Cloze text", @@ -89,7 +89,7 @@ class ClozePlugin implements JsPsychPlugin { ); if (trial.check_answers) { - if (answers[i] !== solutions[i]) { + if (!solutions[i].includes(answers[i])) { field.style.color = "red"; answers_correct = false; } else { @@ -125,12 +125,12 @@ class ClozePlugin implements JsPsychPlugin { } private getSolutions(text: string, case_sensitive: boolean) { - const solutions = []; + const solutions: String[][] = []; const elements = text.split("%"); for (let i = 1; i < elements.length; i += 2) { solutions.push( - case_sensitive ? elements[i].trim() : elements[i].toLowerCase().trim() + case_sensitive ? elements[i].trim().split("/") : elements[i].toLowerCase().trim().split("/") ); } @@ -156,7 +156,7 @@ class ClozePlugin implements JsPsychPlugin { const solutions = this.getSolutions(trial.text, trial.case_sensitivity); const responses = []; for (const word of solutions) { - if (word == "") { + if (word.includes("")) { responses.push(this.jsPsych.randomization.randomWords({ exactly: 1 })); } else { responses.push(word);