WeBWorK Main Forum

$numOfAttempts in custom answer checker (OPL bug #3711)

$numOfAttempts in custom answer checker (OPL bug #3711)

by George Jennings -
Number of replies: 0
This bug: http://bugs.webwork.maa.org/show_bug.cgi?id=3711
in OPL problem: MiamiUOhio/DiffEq/Definitions_and_Terminology/Problem23.pg
seems to be caused by the use of the environmental variable $numOfAttempts in a custom answer checker

ANS( $answer[1]->cmp( checker=>sub {
my ( $correct, $student, $ansHash ) = @_;
if ( ($numOfAttempts < 1) && ($correct == $student) ) {
return 1;
} elsif ( ($numOfAttempts > 0) && ($correct == $student) ) {
Value->Error("Your answer is correct, but your score did not change since you used up the attempts allowed.");
} else {
return 0;
};
}
) );

The author intends to give the student only one chance to answer the question for credit, but it appears that when a student submits an answer WeBWorK increments the environmental variable $numOfAttempts before the answer is graded, so the condition $numOfAttempts < 1 is always false. That prevents students from receiving credit in this problem.

Is increment-before-grading the expected behavior for $numOfAttempts? I want to make sure before I try to fix this problem because many MiamiUOhio problems seem to use the same $numOfAttempts trick so they all may need to be fixed.

A copy of the problem is attached.