// Numbas version: exam_results_page_options {"name": "Answer is NaN or a number", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Answer is NaN or a number", "tags": [], "metadata": {"description": "

The student is asked to find the square root of an integer of the form $\\pm n^2$. If the root is not real, they should enter \"nan\".

\n

A custom marking algorithm extends the built-in one to deal with \"nan\".

\n

There's some custom javascript to set the expected answer correctly. In the future this will be possible in the marking algorithm - see https://github.com/numbas/Numbas/issues/856

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "", "advice": "", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true}, "constants": [], "variables": {"n": {"name": "n", "group": "Ungrouped variables", "definition": "random(NaN,random(1..10))", "description": "", "templateType": "anything", "can_override": false}, "n_squared": {"name": "n_squared", "group": "Ungrouped variables", "definition": "if(isnan(n),-random(1..10)^2,n^2)", "description": "", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["n", "n_squared"], "variable_groups": [], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "numberentry", "useCustomName": false, "customName": "", "marks": 1, "scripts": {"constructor": {"script": "var oldCorrectAnswer = part.getCorrectAnswer;\npart.getCorrectAnswer = function(scope) {\n var minvalue = jme.subvars(this.settings.minvalueString,scope);\n minvalue = Numbas.jme.castToType(scope.evaluate(minvalue),'number');\n if(isNaN(minvalue.value)) {\n this.settings.minvalue = this.settings.maxvalue = Numbas.jme.castToType(minvalue,'decimal');\n return 'nan';\n } else {\n return oldCorrectAnswer.apply(this,arguments);\n }\n}", "order": "after"}}, "customMarkingAlgorithm": "student_wrote_nan (Did the student write \"nan\"?):\n lower(studentAnswer) in [\"nan\",\"not a number\"]\n\nstudentNumber (The student's answer, parsed as a number):\n // If the student wrote \"nan\", override the built-in parsing\n if(student_wrote_nan, NaN, base_studentNumber) \n\nvalidNumber (Is the student's answer a valid number?):\n // If the student wrote \"nan\", their answer is valid.\n // Otherwise, apply the normal logic, which marks all other non-number inputs as invalid.\n if(student_wrote_nan,\n true\n ,\n apply(base_validNumber)\n )\n\nmark:\n if(student_wrote_nan,\n correctif(isnan(settings[\"minvalue\"]))\n ,\n apply(base_mark)\n )", "extendBaseMarkingAlgorithm": true, "unitTests": [{"variables": [{"name": "n", "value": "NaN"}, {"name": "n_squared", "value": "-4"}], "name": "Correct \"nan\"", "answer": {"valid": true, "value": "nan", "empty": false}, "notes": [{"name": "mark", "expected": {"value": "true", "messages": ["Your answer is correct.\n\nYou were awarded 1 mark."], "warnings": [], "error": "", "valid": true, "credit": 1}}]}, {"variables": [{"name": "n", "value": "NaN"}, {"name": "n_squared", "value": "-4"}], "name": "Incorrect when expecting \"nan\" but a number given", "answer": {"valid": true, "value": "2", "empty": false}, "notes": [{"name": "mark", "expected": {"value": "nothing", "messages": ["Your answer is incorrect."], "warnings": [], "error": "", "valid": true, "credit": 0}}]}, {"variables": [{"name": "n", "value": "10"}, {"name": "n_squared", "value": "100"}], "name": "Correct real number", "answer": {"valid": true, "value": "10", "empty": false}, "notes": [{"name": "mark", "expected": {"value": "nothing", "messages": ["Your answer is correct.\n\nYou were awarded 1 mark."], "warnings": [], "error": "", "valid": true, "credit": 1}}]}, {"variables": [{"name": "n", "value": "10"}, {"name": "n_squared", "value": "100"}], "name": "nan is valid but incorrect when expecting a real number", "answer": {"valid": true, "value": "nan", "empty": false}, "notes": [{"name": "validnumber", "expected": {"value": "true", "messages": [], "warnings": [], "error": "", "valid": true, "credit": 0}}, {"name": "mark", "expected": {"value": "false", "messages": ["Your answer is incorrect."], "warnings": [], "error": "", "valid": true, "credit": 0}}]}], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

I'd like to evaluate $\\sqrt{\\var{n_squared}}$.

\n

If it's a real number, enter it below. Otherwise, write nan, for \"not a number\".

", "minValue": "n", "maxValue": "n", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "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/"}]}