// Numbas version: exam_results_page_options {"name": "Multiple answers to a number entry part - custom marking script", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Multiple answers to a number entry part - custom marking script", "tags": [], "metadata": {"description": "
Do not use this: alternative answers are the best way of accepting multiple correct answers.
", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "", "advice": "", "rulesets": {}, "extensions": [], "variables": {"solutions": {"name": "solutions", "group": "Ungrouped variables", "definition": "set(roots)", "description": "", "templateType": "anything"}, "roots": {"name": "roots", "group": "Ungrouped variables", "definition": "repeat(random(-10..10),2)", "description": "", "templateType": "anything"}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["roots", "solutions"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "gapfill", "useCustomName": false, "customName": "", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "Solve $\\simplify{x^2-{roots[0]+roots[1]}x + {roots[0]*roots[1]}} = 0$
\nEnter your answer(s) in the box below, with a comma between each solution.
\n$x = $ [[0]]
\n", "gaps": [{"type": "numberentry", "useCustomName": false, "customName": "", "marks": 1, "scripts": {"constructor": {"script": "// this function is called when the student's answer is submitted.\n// it splits the answer into separate numbers and tidies them up (as strings)\nthis.setStudentAnswer = function() {\n var p = this;\n this.studentAnswer = this.answerList[0].split(',').map(function(answer) { return p.cleanAnswer(answer); });\n}", "order": "after"}, "mark": {"script": "var p = this;\nvar validation = this.validation;\nvalidation.badNumbers = [];\n\n// parse each answer\n// if any answer is not a valid number, this.answered will be false\nvar validNumbers = true;\nvar answers = this.studentAnswer.map(function(s) {\n if( s.length>0 && util.isNumber(s,p.settings.allowFractions) ) {\n return util.parseNumber(s,p.settings.allowFractions);\n } else {\n validNumbers = false;\n validation.badNumbers.push(s);\n }\n})\n\nif(!validNumbers) {\n this.answered = false;\n this.setCredit(0,R('part.numberentry.answer invalid'));\n return;\n}\n\nthis.answered = true;\n\nvar solutions = variables.solutions.map(Numbas.jme.unwrapValue);\n\nconsole.log(solutions);\nconsole.log(answers);\n\nvar non_solutions = answers.filter(function(n) {return !solutions.contains(n)});\nvar missing_solutions = solutions.filter(function(n) {return !answers.contains(n)});\nif(non_solutions.length) {\n this.setCredit(0,\"One or more of your answers is not a solution to the equation.\");\n} else if(missing_solutions.length) {\n this.setCredit(0,\"You did not give every solution to the equation.\");\n} else {\n this.setCredit(1,\"Your answer is correct.\");\n}", "order": "instead"}}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "0", "maxValue": "1", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}