## WeBWorK Problems by Michael Shulman -
Number of replies: 8

If not, is there some way to achieve the same result? 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. 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-> == COMPOSITE) { return$student-> == $f1 &&$student-> == $g1;} elsif($student-> == PRODUCT) {  return $student-> ==$f2 && $student-> ==$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-> ==$correct->, which of course isn't enough. 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->, 1)] eq 'Composite') { return$student-> == $f1 &&$student == $g1; } elsif ($radio->{orderedChoices}[substr($student->, 1)] eq 'Product') { return$student-> == $f2 &&$student == \$g2;
} else {
return 0;
} 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? 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. 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.)  