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.
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.
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?
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.
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.)
I am certain it could be modified to be done. This would need to be done in the parserRadioButtons.pl file.