Difference between revisions of "PopUpLists"

From WeBWorK_wiki
Jump to navigation Jump to search
(add historical tag and give links to newer problems.)
 
Line 1: Line 1:
  +
{{historical}}
  +
  +
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/SimplePopUp.html a newer version of this problem]</p>
  +
 
<h2>Pop-Up Lists (and Solutions)</h2>
 
<h2>Pop-Up Lists (and Solutions)</h2>
   

Latest revision as of 11:29, 16 July 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

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.

Problem Techniques Index

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 parserPopUp.pl macro file in the initialization section.

# 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 menu for the pop-up in the text as part of our problem text.

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 correct_ans() method of the popup object, as suggested here. The text block between SOLUTION(EV3(<<'END_SOLUTION')); and END_SOLUTION is what students will see when solutions are made available.

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 new_select_list(), and then make it into a pop-up list with the call to rf_print_q(). After that, our variable $popup is a(n empty) pop-up list object. The next step is to add the answers that will be displayed in the list, which is done with the call to ra_pop_up_list(). This list of answers is then displayed for each of the questions that we're coding in the pop-up list object.

Next, we define the actual questions to display. This is done with the call to qa, which has a question, answer pair for each question we could display. Here we've defined two questions, and then the correct answer for each (which must be one of the answers that was defined previously).

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 print_q() to create the questions that we are displaying.

  ANS(str_cmp( $popup->ra_correct_ans() )) ;

And in the answer and solutions section, we call the ra_correct_ans() method of the popup list object.

Problem Techniques Index