I have a problem that correctly checks whether three entered points are on a parabola, but it allows the student to enter the same point all three times and still get full credit.
Because the problem is using JSXGraph to generate the coordinates of the points, they are entered in three hidden named answer blanks using:
TEXT(NAMED_HIDDEN_ANS_RULE('point1_coords_ans', 30));
TEXT(NAMED_HIDDEN_ANS_RULE('point2_coords_ans', 30));
TEXT(NAMED_HIDDEN_ANS_RULE('point3_coords_ans', 30));
Currently I am calling the checker using the following code:
NAMED_ANS('point1_coords_ans'=>$answer1->cmp(checker=>~~&point_on_parabola));
NAMED_ANS('point2_coords_ans'=>$answer2->cmp(checker=>~~&point_on_parabola));
NAMED_ANS('point3_coords_ans'=>$answer3->cmp(checker=>~~&point_on_parabola));
And the checker itself is:
# Custom answer checker that checks to see if a point is on the line
sub point_on_parabola
{
my ($correct, $student, $ansHash) = @_;
my ($x, $y) = $student->value;
if (abs($a * $x*$x + $b * $x + $c - $y) < 0.01) { return 1; }
Value->Error("The point graphed is not on the parabola.") if not $ansHash->{isPreview};
return 0;
}
Thanks!
Paul