Difference between revisions of "ErrorMessageCustomization"
m |
m |
||
Line 51: | Line 51: | ||
<b>Setup:</b> |
<b>Setup:</b> |
||
First, specify a Context. One way to remap the error message |
First, specify a Context. One way to remap the error message |
||
− | is through the context. In factoring <code>-x+2</code> as |
+ | is through the context. In factoring <code>-x+2</code> as |
+ | <code>-(x-2)</code>, students |
||
may enter <code>-</code> instead of <code>-1</code> in the |
may enter <code>-</code> instead of <code>-1</code> in the |
||
first answer box and receive the error |
first answer box and receive the error |
||
Line 60: | Line 60: | ||
it is nonempty. To generate a blank error message, use a quoted |
it is nonempty. To generate a blank error message, use a quoted |
||
space <code>" "</code>, not <code>""</code>. |
space <code>" "</code>, not <code>""</code>. |
||
+ | </p> |
||
+ | <p> |
||
+ | For another way to customize the error message, see the |
||
+ | Answer Evaluation section below. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 98: | Line 102: | ||
<p> |
<p> |
||
<b>Answer Evaluation:</b> |
<b>Answer Evaluation:</b> |
||
− | As is the answer. |
||
+ | Another way to remap the error message "Missing operand after '-'" would be to use a post-filter to remove the message after the answer has been graded. The <code>answerHints.pl</code> file provides one way to do this, but it is probably just as easy to do it manually, as in: |
||
+ | <pre> |
||
+ | ANS($eqn->cmp->withPostFilter(sub { |
||
+ | my $ans = shift; |
||
+ | $ans->{ans_message} = "Enter '-1' instead of '-'" |
||
+ | if $ans->{ans_message} eq |
||
+ | "Missing operand after '-'"; return $ans; |
||
+ | })); |
||
+ | </pre> |
||
+ | |||
</p> |
</p> |
||
</td> |
</td> |
Revision as of 22:38, 26 January 2010
Error Message Customization: PG Code Snippet
This PG code shows how to customize (remap) the error messages students receive after submitting an incorrect response or making a syntax error when entering their answer. This requires using MathObjects or a macro file that loads MathObjects, so that a Context is defined. Note that this is an insertion, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
PG problem file | Explanation |
---|---|
loadMacros("PGstandard.pl","MathObjects.pl"); |
Initialization: To be able to customize the error messages students receive, we must be using MathObjects or a macro that loads MathObjects and has a Context. |
Context("Numeric"); Context()->{error}{msg}{"Missing operand after '-'"} = "Enter '-1' instead of '-'"; $ans1 = Real("-1"); $ans2 = Formula("x-2"); |
Setup:
First, specify a Context. One way to remap the error message
is through the context. In factoring For another way to customize the error message, see the Answer Evaluation section below. |
BEGIN_TEXT Factor \( -1 \) from \( -x+2 \). $BR \( -x + 2 = \) \{ ans_rule(5) \} \( \cdot \big( \) \{ ans_rule(10) \} \( \big) \) END_TEXT |
Main Text: The problem text section of the file is as we'd expect. |
ANS( $ans1->cmp() ); ANS( $ans2->cmp() ); |
Answer Evaluation:
Another way to remap the error message "Missing operand after '-'" would be to use a post-filter to remove the message after the answer has been graded. The ANS($eqn->cmp->withPostFilter(sub { my $ans = shift; $ans->{ans_message} = "Enter '-1' instead of '-'" if $ans->{ans_message} eq "Missing operand after '-'"; return $ans; })); |