Feedback Macros¶
Building the response a student sees after they answer.
There is no feedback variable, and no wrongans / showwork / ifansunit
Earlier versions of this page described a feedback = "…" assignment and
three helper macros. None of them exist — wrongans, showwork and
ifansunit appear nowhere in the engine, and there is no magic feedback
variable.
Feedback in IMathAS works the other way round: a getfeedback* macro
returns a block of HTML, already wrapped with a correct/incorrect icon,
and you place that string where you want it shown.
There are exactly six feedback macros, and all of them return markup.
Where things go¶
The question editor has three boxes, and feedback belongs in the two that display:
| Editor box | Stored as | Role |
|---|---|---|
| Common Control | control |
all code: randomization, variables, $answer and every option |
| Question Text | qtext |
the question as displayed |
| Detailed Solution | solution |
the worked solution shown after the attempt |
Older questions can also carry two legacy code columns. qcontrol ran after control when the question was displayed but not when it was scored, so it must never set $answer; answer ran after control both times. The editor has no box for either: opening such a question appends their code to Common Control.
There is no [number] section header. The answer type is a separate setting on the question (its qtype), not part of any code.
getfeedbackbasic($correct, $wrong, $thisq, $partn)¶
The common case: one message when they got it right, another when they did not.
$fb = getfeedbackbasic(
"Correct — the slope is the coefficient of `x`.",
"Not quite. Look at the coefficient of `x`.",
$thisq
)
$partn selects a part in a multipart question; omit it for single-answer questions.
getfeedbacktxt($stu, $fbtxt, $ans)¶
Per-answer feedback. $fbtxt is an array keyed by the student's answer, so each choice can carry its own explanation — the macro looks up the student's actual response and wraps the matching message. In a multiple-choice question the student's answer is the index of the chosen option in $questions (0-based, before shuffling), and $answer is an index too, so key $fbtxt by index — array(0 => "…", 1 => "…") — not by the option text. The example below is for a number question, where the key must be the exact string the student typed: 7.0 gets the correct icon but no message.
$fbtxt = array(
"3" => "That is `f(1)`, not `f(3)`.",
"7" => "Right — substitute 3 and simplify.",
"9" => "Check the sign on the second term."
)
$fb = getfeedbacktxt($stuanswers[$thisq], $fbtxt, $answer)
$ans may list several accepted answers separated by or; each is tried in turn.
Numeric and function variants¶
| Macro | For |
|---|---|
getfeedbacktxtnumber($stu, $partial, $fbtxt, $deffb, $tol) |
number answers, with a tolerance |
getfeedbacktxtcalculated($stu, $stunum, $partial, $fbtxt, $deffb, $answerformat, $requiretimes, $tol) |
calculated answers |
getfeedbacktxtnumfunc($stu, $partial, $fbtxt, $deffb, $vars, $requiretimes, $tol, $domain) |
function answers, compared over a domain |
getfeedbacktxtessay($stu, $fbtxt) |
essay answers — $fbtxt is one string, shown without an icon once the student has typed anything |
In the number, calculated and function forms, $partial is a flat list of pairs, array(value, credit, value, credit, …), and $fbtxt is a plain list read by pair position: $fbtxt[0] goes with the first pair, $fbtxt[1] with the second, and so on. It is not keyed by the student's answer. The macro shows the message for the first value the answer matches, with a correct icon when that pair's credit is 1 and an incorrect icon when it is below 1. $deffb is the fallback message when nothing in $partial matches; it defaults to "Incorrect". $tol is relative and defaults to .001; prefix it with | (for example "|0.01") for an absolute tolerance.
$fb = getfeedbacktxtnumber(
$stuanswers[$thisq],
array($answer, 1, 9.8, 0),
array("Right.", "Careful — that is `g` in SI units."),
"Check your units and try again."
)
They go quiet during a test — in the legacy player only¶
In the legacy assessment player (assessment/showtest.php), all six macros return an empty string when the assessment's testtype is NoScores or EndScore, so per-question feedback does not leak correctness where scores are withheld. The current player (assess2) never sets testtype, so this check never fires there, and the macros return their feedback whatever the assessment's score-display setting is. Do not rely on the macros to hide feedback in an assessment that withholds scores.
Conditional feedback without a macro¶
The getfeedback* macros cover answer-driven feedback. For anything else, build the string yourself and interpolate it:
$hint = ifthen($b^2 - 4*$c < 0,
"This one has no real roots — check the discriminant first.",
"Both roots are real.")
Then place $hint in the Detailed Solution box.
Wrong units¶
There is no ifansunit. Answers with units are handled by the units-aware answer types and by comparenumberswithunits($unitExp1, $unitExp2, $tol) on the Conditional answer-type page. To give targeted feedback, list the number the student gets in the wrong unit as a $partial value of getfeedbacktxtnumber, as in the example above. That macro strips every character except digits, -, ., e and E before comparing, so it never checks the unit: 9.8 m and 9.8 s are both read as 9.8, 9.8 m/s^2 as 9.82, and 9.8 meters is rejected as not a number. Use it where the student types a bare number.
Showing work¶
There is no showwork macro. A place for students to show their reasoning is not a feedback helper. The current player has a built-in show-work box, turned on through the assessment's or question's show work setting; alternatively, add an essay part to a multipart question. See Multipart and Essay.
See Also¶
- Conditional —
comparenumbers,comparenumberswithunits,comparefunctions - Question Types — the editor boxes and where code goes
- Control Syntax —
if/elseif/else - Math Macros —
ifthen - Multipart — multi-answer questions and
$partn