PopUpLists
This problem has been replaced with a newer version of this problem
Pop-Up Lists (and Solutions)
This is the PG code to use a pop-up list (a.k.a. drop down menu) for answers. It also has the proper syntax for including solutions for students.
Below we consider two ways of including pop-up lists in a problem. The first is simpler, and simply introduces a pop-up somewhere in the text of the problem. The second uses old-style answer evaluators, and is more sophisticated in that it allows us to define multiple questions that use the pop-ups to define possible answers, and then allows selection of a random subset of those to display in the problem.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "parserPopUp.pl", ); TEXT(beginproblem()); |
We don't need any additions to the tagging and description section of the WeBWorK problem, but we do need to include the |
# the arguments of PopUp are [list of answers], # correct answer $popup = PopUp(["?", "one", "two", "three"], "three"); |
Then, in the set-up section of the file we define the pop-up object, which will display as a single pop-up selector. |
BEGIN_TEXT There is/are \{ $popup->menu() \} word(s) written below. $PAR there $BR are $BR three END_TEXT |
In the text section of the file, we then include the |
ANS( $popup->cmp() ); Context()->texStrings; SOLUTION(EV3(<<'END_SOLUTION')); $PAR SOLUTION $PAR The correct answer is \{ $popup->correct_ans() \} words. END_SOLUTION Context()->normalStrings; ENDDOCUMENT(); |
And then we can check the answer for the pop-up list as we'd expect.
Note that if we want to include the answer to the pop-up list in the solution (or somewhere else), we can do that by using the
|
Using pop-up lists with the old-style answer evaluators is somewhat more complicated, because the code is trying to do more than the new MathObjects based pop-up object is. In particular, it is designed to flexibly allow multiple pop-up questions from which a subset is selected.
PG problem file | Explanation |
---|---|
$popup = new_select_list(); $popup->rf_print_q(~~&pop_up_list_print_q); $popup->ra_pop_up_list( [ No_answer => "", True => "T", False => "F" ] ); $popup->qa("This is a pop-up question", "T", "This problem has two questions", "T"); $popup->choose(2); |
To include a pop-up list we need make no changes to the first two sections of the WeBWorK PG file (documentation and tagging, and problem initialization). In the set-up section, we have to define the list. Note that because we're allowing ourselves to create several pop-up questions and then select from among those, the set-up defines several questions in this case.
We first initialize a select list by calling
Next, we define the actual questions to display. This is done with the call to Finally, we select some number of the questions to display. Here, we've opted to display both of the questions (in a random order). |
\{ $popup->print_q() \} |
In the text section of the problem, we call |
ANS(str_cmp( $popup->ra_correct_ans() )) ; |
And in the answer and solutions section, we call the |