Answer Hints

Shows how to provide answer hints to students.

Complete Code

Download file: AnswerHints.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'answerHints.pl', 'PGcourse.pl');

Preamble

Make sure the answerHints.pl macro is loaded.

Context()->variables->are(t => 'Real', u => 'Real');

$f   = Formula('2 t');
$ans = Formula('6 u')->cmp->withPostFilter(AnswerHints(
    Formula('6 t') => 'Are you using the correct variable?',
    Formula('6 u') => 'Good work!'
));

Setup

To generate specific, customized answer hints for particular answers, we use the AnswerHints postfilter provided by answerHints.pl. The answer hints should be provided by a particular answer, followed by the hash table association operator =>, followed by a string that will show up in the messages portion of the answer preview and feedback box when students submit their answers. You may include as many answer and hint pairs as you like, and even use subroutines in them (see answerHints.pl for more on this).

If the same error message should be given for several different answers, you should make a square bracketed list of those answers. For example, if the variables x, t, and u were all in the context, we could use

 $ans->cmp->withPostFilter(AnswerHints(
     [ Compute('6 t'), Compute('6 x') ] =>
         'Are you using the correct variable?'
 ))

If the MathObjects answer evaluator normally generates a message, the default is not to change a message that is already in place. To override a message generated by a MathObjects answer evaluator, you should set replaceMessage => 1 as below.

 $ans->cmp->withPostFilter(AnswerHints(
     Compute('6 u') => [ 'Good work!', replaceMessage => 1 ]
 ))
BEGIN_PGML
If [`f(t) = [$f]`], then [`f(3u)`] = [____]{$ans}

[@ knowlLink(
    'Click for a hint',
    value => 'Substitute \(3u\) wherever you see \(t\) in the formula for \(f\).'
) @]*
END_PGML

Statement

Knowls (little bits of knowledge) provide an always present link to a hint that expand to reveal the hint when clicked on, and collapse to hide the hint when clicked on again.

BEGIN_PGML_HINT
Substitute [`3u`] wherever you see [`t`] in the formula for [`f(t) = [$f]`].
END_PGML_HINT

ENDDOCUMENT();

Hint

This is a hint that is revealed to students only after a certain number of submissions. The number of submissions before the hint is shown is specified by the instructor in webwork settings.

These hints are added to the problem in the block of text between the commands BEGIN_PGML_HINT and END_PGML_HINT, which must be on their own lines and at the start of a line. The hint will automatically generate the word HINT: before the block of text that is the hint, so you should not add it manually.