WeBWorK Main Forum

popup with numbers turns into array index

popup with numbers turns into array index

by Andras Balogh -
Number of replies: 3

Using 'parserPopUp.pl' and  numbers in between quotes like $popup = PopUp(["Choose one", "0", "1", "2"], "1"); seems to turn the answer into index, and "0" is accepted as correct answer (which has index 1). Similarly, popup = PopUp(["Choose one", "0", "1", "2"], "0"); accepts "Choose one" as correct answer having zero index.


This is from LibraryUMN/algebraKaufmannSchwitters/ks_6_4_6.pg

I don't know if this is a new issue in V.2.19 but I used this problem before without students complaining. I rewrote the numbers to words and then it works correctly.


In reply to Andras Balogh

Re: popup with numbers turns into array index

by Danny Glin -

I believe this has always been the way that PopUps work.  It certainly has been that way in versions prior to 2.19, so it's possible that this problem never worked properly.

If the correct answer to a PopUp is given as an integer, then by default it is assumed that the integer represents the index of the correct answer in the array of answers.  If you want to force the correct answer to represent the entry itself you need to add the noindex => 1 option.

As of 2.18 the DropDown construction is available, which allows you to add a non-selectable default choice, so now the better way to code this problem is

$popup = DropDown(["0", "1", "2"], "0",placeholder=>"Choose one",noindex=>1);

This still shows "Choose one" as the default for the drop-down menu, but that is not selectable as an answer.

Note that in this specific example noindex=>1 would be unnecessary since the indices of the answers happen to match the values of the answers.

I will fix the problem in the OPL.

In reply to Andras Balogh

Re: popup with numbers turns into array index

by Alex Jordan -

I think this was a change with 2.19 as part of a larger straightening out of inconsistent behaviors between the various multiple choice macro libraries.

See the POD for parserPopUp.pl, in particuar the "noindex" option.

If you end up editing problem files anyway, you may want to move to DropDown() instead of PopUp.