## WeBWorK Problems

by Michael Shulman -
Number of replies: 8
Is it possible for a MultiAnswer to include a radio button group as one of its answers, in addition to ordinary answer blanks?

If not, is there some way to achieve the same result?

In reply to Michael Shulman

### Re: MultiAnswer containing a radio button?

by Glenn Rice -

Yes, this can be done.  I think there is something on the webwork documentation wiki somewhere about this, but I can't find it right now.  So I attached a quick example of this.

In reply to Glenn Rice

### Re: MultiAnswer containing a radio button?

by Michael Shulman -

Thanks!  What is the type of the element of $student corresponding to the radio button group, and how do I compare it against something other than the corresponding element of$correct?

I'm trying to write a problem that shows a function and asks the student to choose whether it is a sum, a product, a quotient, or a composite, and what the two constituent functions are.  Some functions, like sin(x)^2, can be written either as a composite or a product, and so I want both "composite, sin(x), x^2" and "product, sin(x), sin(x)" to be marked correct.  So I want the answer checker to do something like

if($student->[0] == COMPOSITE) { return$student->[1] == $f1 &&$student->[2] == $g1;} elsif($student->[0] == PRODUCT) {  return $student->[1] ==$f2 && $student->[2] ==$g2;} else {  return 0}

(with singleResult set to 1).  But I can't figure out what to put where I've written COMPOSITE and PRODUCT above.  I've tried the numerical indices, the strings, and the labels, but I can't come up with any comparison that is ever true except $student->[0] ==$correct->[0], which of course isn't enough.

In reply to Michael Shulman

### Re: MultiAnswer containing a radio button?

by Glenn Rice -
Assuming you have defined the radio buttons with something like:
$radio = RadioButtons([['Composite', 'Product', 'Sum', 'Etc']], 0, labels => "ABC"); then you can use: if ($radio->{orderedChoices}[substr($student->[0], 1)] eq 'Composite') { return$student->[1] == $f1 &&$student[2] == $g1; } elsif ($radio->{orderedChoices}[substr($student->[0], 1)] eq 'Product') { return$student->[1] == $f2 &&$student[2] == \$g2;
} else {
return 0;
}
In reply to Glenn Rice

### Re: MultiAnswer containing a radio button?

by Michael Shulman -

That did it!  Thanks.

This should indeed be recorded on the wiki somewhere if it isn't already (and I couldn't find it there either).  I'd be happy to add it; where would be a good place?

In reply to Michael Shulman

### Re: MultiAnswer containing a radio button?

by Glenn Rice -

I am not sure that this classifies as something that should be documented.  This is hacking around a bit in the internals of the parserRadioButtons.pl macro.

In reply to Glenn Rice

### Re: MultiAnswer containing a radio button?

by Michael Shulman -

But if there isn't any other way to achieve this result, then it's a useful thing for people to know how to do.  Could the webwork code be modified to enable a less hacky way to do this?  (I'd be happy to try to write such a modification myself if you tell me where in the code it should go.)

In reply to Michael Shulman

### Re: MultiAnswer containing a radio button?

by Glenn Rice -
There are lots of useful things to be found in the WeBWorK code. The problem with hacking into things like this is that there is no guarantee that the parserRadioButtons.pl code won't change at some point. The orderedChoices hash key could be removed or renamed, or its usage could change in some way so that this wouldn't work anymore.

I am certain it could be modified to be done. This would need to be done in the parserRadioButtons.pl file.