PREP 2015 Question Authoring - Archived

Radio Buttons

Radio Buttons

by Daniele Arcara -
Number of replies: 3
I successfully created a problem with a drop down menu listing possible answers. I then decided to try the same problem with the answers listed as radio buttons, but I am getting weird warning messages.

The warning messages say:
  • Use of uninitialized value $value in string eq at line 181 of [PG]/macros/parserRadioButtons.pl
  • Use of uninitialized value $label in string eq at line 335 of [PG]/macros/parserRadioButtons.pl
 Here is my code:

DOCUMENT();        # This should be the first executable line in the problem.

loadMacros(
  "PGstandard.pl",
  "PGML.pl",
  "PGcourse.pl",
  "parserRadioButtons.pl",
);

TEXT(beginproblem());

$a = random(2,4,1);
$b = random(5,7,1);
$c = random(2,8,1);
$radio = RadioButtons(["convergent", "divergent"], "convergent", );

#######################################################
#
#  Determine if a geometric series is convergent or divergent.
#

BEGIN_PGML
The geometric series [` \displaystyle\sum_{n=0}^\infty \frac{[$c]\cdot[$a]^n}{[$b]^n} `] is

[______________]{$radio}.
END_PGML

#######################################################

ENDDOCUMENT();        # This should be the last executable line in the problem.
In reply to Daniele Arcara

Re: Radio Buttons

by Paul Pearson -
Hi Daniele,

The radio buttons do not actually use an answer blank, so [_____]{$radio} is not the right thing to use.  Instead, you need to call the ->buttons() method on the $radio object to generate the list of radio button options that will be displayed to the students.  This requires being in Perl mode using [@ @] and also interpreting the output as html using a * after @].  Then, to handle the answer evaluation, you should call the ->cmp() method on the $radio object that compares the student answer to the correct answer, and finally use ANS(); to record the results in WebWork's database.  In short, use [@ $radio->buttons() @]* in the displayed text portion and ANS( $radio->cmp() ); after the displayed text portion.  We will be covering things like this in future workshops, too.

Best regards,

Paul Pearson

############  Begin PGML snippet ###################

BEGIN_PGML
The geometric series [` \displaystyle\sum_{n=0}^\infty \frac{[$c]\cdot[$a]^n}{[$b]^n} `] is

[@ $radio->buttons() @]*
END_PGML

ANS($radio->cmp());

############ End PGML snippet #####################
In reply to Paul Pearson

Re: Radio Buttons

by Davide Cervone -
Actually, you should be able to use RadioButtons in the way Daniele suggested (but this was made possible by fairly recent changes to parserRadioButtons.pl, so that is why you don't know about it). But it turns out there is a bug in the code for RadioButtons which caused the problem. I've fixed the problem and put a copy of the modified file in the course templates/macros directory, so the original problem should work now in this course. I will make a pull request for the change to be included into the official PG copy, but it will take a while for that to make its way into a release.