WeBWorK Problems

Answer checker to check that multiple answers are different

Answer checker to check that multiple answers are different

by Paul Seeburger -
Number of replies: 6
Is it possible to refer to various named answer blanks in an answer checker running on one of them?

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
In reply to Paul Seeburger

Re: Answer checker to check that multiple answers are different

by Paul Seeburger -
Ok, although I was not able to find a solution to this issue in the context of the answer checker, I was able to modify the JavaScript portion of the problem to submit an error message for the answer blank when the points coincide.

This took care of the issue for me.

But if there is a way to refer to the answers to the other answer blanks from an answer checker, it would still be nice to know about.

Thanks!

Paul
In reply to Paul Seeburger

Re: Answer checker to check that multiple answers are different

by Glenn Rice -
I ran into this problem with the line graphing problem that I gave you a while back. What I did was to encode the JSXGraph grapher in such a way that it does not allow one point to be created on top of another, and furthermore the code enforces that one point can not be drug on top of another.
In reply to Glenn Rice

Re: Answer checker to check that multiple answers are different

by Paul Seeburger -
Thanks, Glenn!

I did something like this for the parabolas too.  But how did you enforce that one point cannot be dragged on top of another?  I haven't accomplished this, although, I did report an error to WeBWorK whenever the x-coordinates of the points were the same (since this does not allow a parabola to be drawn).

I guess I better go back and modify my line drawing problems too before next semester.  I was wondering about that once I recognized this issue here.

Paul
In reply to Paul Seeburger

Re: Answer checker to check that multiple answers are different

by Glenn Rice -
One way to prevent one point from being drug onto another is to add a 'drag' event handler that checks during a drag if a point is over another and then sets the position of the point to be somewhere close if it is. Use something like:

function pointDrag(e)
{
Check if point is over another here.
If so move it a bit. For example with
this.setPosition(JXG.COORDS_BY_USER, [this.X(), this.Y() - 1])
}

When the point is created use
point.on('drag', pointDrag);
to connect the event handler to the point.
In reply to Paul Seeburger

Re: Answer checker to check that multiple answers are different

by Gavin LaRose -
Hi Paul,

It might be possible to do this with a MultiAnswer problem checker, as described in the problem techniques pages. The one issue is that this doesn't, I think, provide a mechanism for hiding the answer blanks.

Which is to say, "no," I don't have any good solution, but if it were possible to tweak the answer blanks generated by the MultiAnswer object it would address the problem nicely.

For what it's worth,
Gavin

In reply to Paul Seeburger

Re: Answer checker to check that multiple answers are different

by Steve Dalton -
Hi Paul,

One way that I've used recently is to have one NAMED_HIDDEN_ANS and to use a list answer checker.  On the Javascript side, I use JSXGraphs's on method to provide a callback function for whenever a point is moved.  This method writes the points' coordinates to the hidden answer field as if a student is entering a list of points (so each point surrounded by parentheses, and each point separated by a comma).  You can then (in Point context) just do a list answer checker.

HTH,
Steve