WeBWorK Problems

RadioButtons with several correct answers

RadioButtons with several correct answers

by Rick Lynch -
Number of replies: 3

Hi! I am writing a question using radio buttons where more than one possibility is correct. To further complicate things, the choices are images. I tried following the same approach here, which uses a popup instead, https://webwork.maa.org/moodle/mod/forum/discuss.php?d=3531, but it gives an error that 'one' is not defined in the context (code below). 

My questions are:

  1. Is it possible to allow more than one answer to be counted as correct using radio buttons by fixing the code below?
  2. How would this change, if at all, if the radio button choices are images? (such as image("image.jpg", width=>"350"))

Note that I could probably work around Radio Buttons by assigning letters to the images and having students type in the correct letter(s), but I wanted to see if the above is possible.

Thanks so much in advance!

DOCUMENT();

loadMacros(
    "PGstandard.pl",
    "MathObjects.pl",
    "PGML.pl",
    "parserRadioButtons.pl",
    "parserOneOf.pl",
);

TEXT(beginproblem());
COMMENT('');

Context("Numeric");

@choices = ("?","one", "two", "three");
$radio = RadioButtons([[@choices]], $choices[0]);
Context($radio->context);

BEGIN_PGML

What number is less than three?

[@ $radio->buttons @]*

END_PGML

ANS(OneOf(@choices[1,2])->cmp());

ENDDOCUMENT();
In reply to Rick Lynch

Re: RadioButtons with several correct answers

by Alex Jordan -

What version of WeBWorK is this for?

A radio button interface is only for one correct answer. It's like an old radio where you push one button down, and that automatically pops up any other button that was depressed.

What you want is checkboxes. Prior to 2.18, there was a tool for checkboxes in PGchoicemacros.pl, but it had certain issues. With 2.18, there is parserCheckboxList.pl.

In reply to Rick Lynch

Re: RadioButtons with several correct answers

by Danny Glin -
parserOneOf.pl is intended for questions where there is more than one correct answer, but you want to give students credit if they enter any one of the correct answers.

Do you want students to choose one correct answer, or choose all correct answers?

For choosing all correct answers parserCheckboxList.pl is the way to go, as Alex suggests.

If there is more than one correct answer and you just want students to select any one of them then you may need a custom answer checker along with parserRadioButtons.pl.
In reply to Danny Glin

Re: RadioButtons with several correct answers

by Rick Lynch -

Thank you for your answers, Alex and Danny!

Yes, I would like to go the custom answer checker route with parserRadioButtons.pl as I'd like them only to be able to select one answer, but it would accept, say, if they select either the first or the second answer. However, I wasn't able to figure out how to with Radio Buttons. Typically, I'd do something like define the $altCorr answer and then do something like:

sub checker => {

  my ($corr,$stud,$a) = @_;

  return $stud == $corr || $stud == $altCorr;

}

or use parserOneOf.pl.

Any insights are greatly appreciated!