[ww-bugs] Bug 3718: parserRadioButtons.pl throws a warning, does not have correct answer as correct

bugzilla-daemon at webwork.maa.org bugzilla-daemon at webwork.maa.org
Wed Aug 31 12:22:42 EDT 2016


http://bugs.webwork.maa.org/show_bug.cgi?id=3718





--- Comment #3 from Davide P. Cervone <dpvc at union.edu>  2016-08-31 12:22:42 ---
I was just getting ready to respond to you when your recent messages came in
today.

The RadioButtons (and PopUp menu) macros allow you to give the correct answer
in one of two different ways:  either as the correct answer string, or as a
numeric index into the correct answers.  Unfortunately, this means there is an
ambiguity in the case that the correct answer is an integer.  Because Perl does
not distinguish between strings and numbers (it converts between them as
needed), there is no way to tell '75' from 75, and so the RadioButtons macro
has to treat these both the same.

For historical reasons, RadioButtons resolves the ambiguity in favor of a
numeric index (as the line you point to indicates, though the \d+ means ONE or
more digits, not TWO or more).  So in your case, the '75' is indicating the
75th entry in the correct answer array, which is undefined, and that leads to
the error message you are getting (and it the correct answer being the first
one by default).  

There are two ways to resolve this in your problem.  Either use

    RadioButtons(['65','75','85','95'],1);

or include spaces in the answers so they don't appear as numbers, as in the
following:

    RadioButtons([' 65 ',' 75 ', '85 ',' 95 '],' 75 ');

It would be better for RadioButtons to issue an error message if the index is
out of range, but that doesn't currently happen.  I will submit a pull request
that does that.  But the ambiguity between index and string will remain.  It
would be possible to add an option like noindex=>true or something to prevent
the interpretation of numbers as indices, I suppose.

-- 
Configure bugmail: http://bugs.webwork.maa.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.


More information about the webwork-bugs mailing list