// Numbas version: exam_results_page_options {"name": "Adrian's copy of 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": [{"variable_groups": [], "rulesets": {}, "showQuestionGroupNames": false, "ungrouped_variables": ["roots", "solutions"], "metadata": {"description": "", "notes": "", "licence": "Creative Commons Attribution 4.0 International"}, "advice": "", "name": "Adrian's copy of Multiple answers to a number entry part - custom marking script", "functions": {}, "variables": {"solutions": {"description": "", "definition": "set(roots)", "group": "Ungrouped variables", "templateType": "anything", "name": "solutions"}, "roots": {"description": "", "definition": "repeat(random(-10..10),2)", "group": "Ungrouped variables", "templateType": "anything", "name": "roots"}}, "preamble": {"js": "", "css": ""}, "tags": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "question_groups": [{"pickingStrategy": "all-ordered", "pickQuestions": 0, "questions": [], "name": ""}], "statement": "", "type": "question", "parts": [{"prompt": "

Solve $\\simplify{x^2-{roots[0]+roots[1]}x + {roots[0]*roots[1]}} = 0$

\n

Enter your answer(s) in the box below, with a comma between each solution.

\n

$x = $ [[0]]

\n

", "scripts": {}, "gaps": [{"scripts": {"mark": {"order": "instead", "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}"}, "constructor": {"order": "after", "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}"}}, "minValue": "0", "showPrecisionHint": false, "correctAnswerFraction": false, "allowFractions": false, "showCorrectAnswer": true, "marks": 1, "variableReplacements": [], "type": "numberentry", "variableReplacementStrategy": "originalfirst", "maxValue": "1"}], "showCorrectAnswer": true, "variableReplacementStrategy": "originalfirst", "variableReplacements": [], "marks": 0, "type": "gapfill"}], "contributors": [{"name": "Adrian Jannetta", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/164/"}]}]}], "contributors": [{"name": "Adrian Jannetta", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/164/"}]}