help logoLON-CAPA Help

Custom Response is a way to have a problem graded based on an algorithm. The use of this response type is generally discouraged, since the responses will not be analyzable by the LON-CAPA statistics tools.

For a single textfield, the student's answer will be in a variable $submission. If the Custom Response has multiple textfields, the answers will be in an array reference, and can be accessed as $$submission[0], $$submission[1], etc.

The student answer needs to be evaluated by Perl code inside the < answer > -tag. Custom Response needs to include an algorithm that determines and returns a standard LON-CAPA response. The most common LON-CAPA responses are:

The answerdisplay is shown instead of the student response in 'show answer' mode after the answer date. The following example illustrates this:
<startouttext />Accept an answer of around 90 or -90<endouttext />
  <customresponse answerdisplay="something near 90 or -90">
    <answer type="loncapa/perl">
# This examples uses perl 'regular expressions' for string evaluation. 
# Consult a perl reference for help understanding the regular expressions.
# We do not want a vector
if ($submission=~/\,/) { return 'EXTRA_ANSWER'; }
# Need a numerical answer here
if ($submission!~/^[\d\.\-\e]+$/i) { return 'WANTED_NUMERIC'; }
if ($difference==0) { return 'EXACT_ANS'; }
if ($difference < 0.1) { return 'APPROX_ANS'; }
return 'INCORRECT';</answer>
    <textline readonly="no" />

Full list of possible return codes: