What version of WeBWorK are you running? When I run your code on 2.17 I do get feedback messages when I enter incorrect answers. For example if I type "functionf" I get the message "Variable 'f' is not defined in this context".

This is the expected behaviour. If you do not explicitly set a context then it defaults to the "Numeric" context, which is for handling real-valued functions and numerical responses. In your code you have added the string "function" to the context, so it recognizes that string along with the strings that are already present in the context (e.g. "DNE", "infinity"). In the Numeric context WeBWorK defaults to expecting a number as the correct answer. If you enter anything that doesn't fit into that context it gets marked wrong before it even gets to the answer checker, and gives a related message.

What this means is that for your code answers such as "function", "3", and "DNE" will be marked correct, because they are allowed answers in the context. Answers such as "functionf" should get the message I quoted above, because the 'f' is not allowed. Answers such as "3x" should get the message "Your answer isn't a number (it looks like a formula that returns a number)".

If you want students to be able to type arbitrary strings you should use the ArbitraryString context, which allows students to enter any text without WeBWorK trying to interpret it as math.

Here's sample problem code that should do what you intended. I've also added the flag to turn off MathQuill (the assistive math formula editor) for this answer, which will prevent the answer box from interpreting the input as a mathematical formula. My code uses PGML syntax, which is the current recommended approach rather than the old BEGIN_TEXT/END_TEXT syntax.

DOCUMENT();

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"contextArbitraryString.pl",

"PGML.pl",

"PGcourse.pl"

);

TEXT(beginproblem());

Context("ArbitraryString");

$ans = String("function")->cmp(mathQuillOpts => "disabled",

checker => sub {

return 1;

}

);

BEGIN_PGML

A [_]{$ans}{10} from [` A `] to [` B `] is a rule that assigns, to each [` x\in A `], a unique element [` y \in B `].

END_PGML

ENDDOCUMENT();