## 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->[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.

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;
}

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.