WeBWorK Problems

Disabling all error messages from a context

Disabling all error messages from a context

by Adam Weyhaupt -
Number of replies: 3
We want to use Webwork to create a "competency quiz" for use in our math for elementary teachers course. For example, we want to require that students simplify

sqrt(8) - sqrt(2)

and the only acceptable answer to us is sqrt(2).

It's easy enough using contexts to do this, for example:

$a = Formula("sqrt(8)");
$b = Formula("sqrt(2)");

$ans = Compute("sqrt(2)");


Enter a value for \($a - $b\) \{ans_rule(35)\}



However, in a gateway quiz, if students hit the "preview" button, they are told that, for example "-" is not allowed in this context.

Is it possible for sqrt(8)-sqrt(2) to fail silently without highlighting the minus sign and warning students? We would like for them to not know at the preview stage that this would be marked incorrectly. The same question could be asked of decimals, etc.

Any advice?


In reply to Adam Weyhaupt

Re: Disabling all error messages from a context

by Davide Cervone -
Well, you could add a post-filter to the answer checker that clears the error messages in preview mode. Something like:
    ANS($ans->cmp->withPostFilter(sub {
      my $hash = shift;
      $hash->{ans_message} = "" if $hash->{ans_message} && $hash->{isPreview};
      return $hash;
which will prevent ANY message from being displayed for preview (including syntactic errors). You could look for specific messages to remove if you want to be more discerning, but then run the risk of letting some unwanted messages through.

Note that this requires you to modify the problems in order to have this effect, so you would need to have special versions for your quiz bank. (I would not want to see such problems filter into the NPL, in general.) Making it happen "automatically" for existing problems without modification would be more difficult.


In reply to Davide Cervone

Re: Disabling all error messages from a context

by Adam Weyhaupt -
Thank you, this is perfect!

I added the additional line:

$hash->{student_ans} = $hash->{original_student_ans} if $hash->{ans_message} && $hash->{isPreview};

so that the yellow syntax highlighting was also disabled. In fact, I think that we will just disable the preview display on essentially all of these questions.

I agree that problems with this modification should not be in the NPL. However, for the specific purpose that we are using these questions for we have a pedagogical need for removing these hints.

We actually will create now two sets of problems: practice problems WITH the hints and quiz questions without.

Thanks a bunch for your help!

In reply to Adam Weyhaupt

Re: Disabling all error messages from a context

by Davide Cervone -
Yes, you are right to put back the original student answer in that case. (It would be possible to put back the stringified MathObject, if one was actually produced, as is the case when the error message is for reasons other than a syntax error, but it is probably not worth it.)

You can, of course, put your post-filter in a macro file as

   $noMessages = sub {
and then use
in the problem, to make it easier.

I understand your pedagogical need, and was not suggesting that you not modify the problems, only that they not be distributed as part of the NPL, where people might not realize their special purpose.

Good luck with the quizzes.