ErrorMessageCustomization

From WeBWorK_wiki
Revision as of 23:30, 26 January 2010 by Pearson (talk | contribs) (New page: <h2>Error Message Customization: PG Code Snippet</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3p...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

Problem Techniques Index

PG problem file Explanation
loadMacros("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 -x+2 as -(x-2), students may enter - instead of -1 in the first answer box and receive the error message Missing operand after '-'. We can replace this error message with "Enter '-1' instead of '-'" via the Context()->{error}{msg} .... code to the left. The replacement error message can be anything you like as long as it is nonempty. To generate a blank error message, use a quoted space " ".

Notes: on using this and related Contexts.

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: As is the answer.

Problem Techniques Index