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

Setup

To generate specific, customized answer hints for particular answers, use the ‘AnswerHints’ post-filter 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 details).

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

$ans->cmp->withPostFilter(AnswerHints(
    [ Compute('6t'), Compute('6x') ] => '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, set replaceMessage => 1 as below.

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

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

Statement

Knowls (little bits of knowledge) insert a button that will open modal dialog containing the hint when activated.

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. The hint will automatically generate the word “HINT” before the block of text that is the hint, so you should not add it manually.