WeBWorK Problems

popup hints after each try

Re: popup hints after each try

by Davide Cervone -
Number of replies: 0
The num_of_correct_ans and num_of_incorrect_ans values are only maintained properly when the problem is part of an actual homework set. If you are using it through the Library Browser, then your answers are not stored, and neither is the number right or wrong, so you should always see the first hint when you submit an answer. So you should add the problem to an actual problem set when you are testing it, even when you are still working on it.

But when you do this, that means once you have submitted answers, they will stay recorded, so you can't go back to earlier hints, even if you have changed the problem file. In order to overcome that (for testing purposes) you can add a test for a special "reset" answer in the grader so that you can reset the problem back to its initial values.

For example:

    install_problem_grader(sub {
      my ($result,$state) = avg_problem_grader(@_);
      if ($inputs_ref->{AnSwEr1} eq 'reset') {
        $state->{num_of_correct_ans} = 0;
        $state->{num_of_incorrect_ans} = 0;
        $state->{recorded_score} = 0;
        $result->{score} = 0;
      } elsif ($state->{num_of_correct_ans} == 0) {
        my $n = $state->{num_of_incorrect_ans} - 1;
        $n = $#hints if $n > $#hints;
        if ($n >= 0) {
          $result->{msg} .= '</i><p><b>Note:</b> <i>' if $result->{msg};
          $result->{msg} .= $hints[$n];
        }
      }
      ($result,$state);
    });
Here, the first answer blank is checked to see if you have entered the word "reset", and if so, the problem is reset so that is appears like you are trying it for the first time.

See if that resolves your issue. (You will, of course, want to remove the reset code when you are done editing the problem.)

Davide