## WeBWorK Problems

### Custom Error Messages Issue

by Brittni Lorton -
Number of replies: 3
I am attempting to add a custom error message to a specific problem and I seem to be running into an issue. The answer to this is the string "None" but I want to allow students to be able to enter points without a strange error message throwing them off. Ideally what I want is:

• If student enters a number -> an error message saying "Your answer is not a point"
• If a student enters a point -> no extra error message, just "Incorrect"
Below is what I have so far. When I type a number in I get the desired message of "Your answer isn't a point", but the problem is that when I enter a point, the error message that still pops up is "Your answer isn't a number (it looks like a point)".
Any help would be greatly appreciated.

Thanks,
*Brittni

###########################
# Initialization

DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",,
"parserAssignment.pl",
"PGML.pl",
"PGcourse.pl",
"contextLimitedPoint.pl",
);

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;$refreshCaschedImages = 1;

##########################
# Setup
Context("Numeric");

##Random variables for slope ##
$a=list_random(0,1); ##formulas for x(t) and y(t)## Context()->noreduce('(-x)-y','(-x)+y');$x_t=Formula("t+(1/t)")->reduce;
$y_t=Formula("t-(1/t)")->reduce; Context("LimitedPoint"); ## Maybe this is needed to allow students to enter a point without an error message, even though the answer is "none" here.$blank = Point("(1,2)");

$pointChecker = sub { my ($correct,$student,$ansHash) = @_;
Value->Error("Your answer isn't a point.") unless $student->class eq "Point"; return 1; }; ################################# ##Main text## BEGIN_PGML Given the parametric curve [ \displaystyle x(t)=[$x_t], \hspace{.25cm} y(t)=[$y_t] ]. Find all the points on the curve at which the slope of the tangent line is [m=[$a] ].

Enter your solution as a comma separated list of ordered pairs [(x,y)] or if there are no points on the curve at which the slope of the tangent line is the given slope enter NONE.

END_PGML

ANS(String("NONE")->cmp(checker=>$pointChecker)->withPostFilter(sub { my$ans = shift;
$ans->{ans_message} = "Incorrect" if$ans->{ans_message} eq "Your answer isn't a number (it looks like a point)";
return \$ans;
}));

#################################
# Solution

#BEGIN_PGML_SOLUTION
#Solution explanation goes here.
#END_PGML_SOLUTION

COMMENT('Uses PGML.');

ENDDOCUMENT();

### Re: Custom Error Messages Issue

by Alex Jordan -
Hi Brittni,

I think you are interested in the typeMatch key described here:
http://webwork.maa.org/wiki/StringsInContext

Alex

### Re: Custom Error Messages Issue

by Davide Cervone -