# add new macro parserWordCompletion.pl #258

Closed
wants to merge 1 commit into from
Closed

wants to merge 1 commit into from

## Conversation

Member

### paultpearson commented Nov 30, 2015

 Provides free response, fill in the blank questions with interactive help. As a student types their answer into the answer blank, jQuery's autocomplete feature generates a drop-down list of allowable answers that match what has already been typed. When the student presses the "Check Answers" or "Submit Answers" button, jQuery generates a warning message if the student answer is not one of the allowable answers. Choices in the drop-down list and the correct answer are specified by the problem author. WordCompletion objects are compatible with Value objects, and in particular, can be used with MultiAnswer objects.
 add new macro parserWordCompletion.pl 
 3453b8c 
Provides free response, fill in the blank questions with interactive help.  As a student types their answer into the answer blank, jQuery's
autocomplete feature generates a drop-down list of allowable answers that match what has already been typed.  When the student presses the "Check Answers" or "Submit Answers" button, jQuery generates a warning message if the student answer is not one of the allowable answers.  Choices in the drop-down list and the correct answer are specified by the problem author.  WordCompletion objects are compatible with Value objects, and in particular, can be used with MultiAnswer objects.
Member

### mgage commented Dec 4, 2015

 Paul, Could you post an example of a problem using this macro in the comment? I can use that to test it. The example question which you sent me earlier doesn't quite work -- probably because of incompatibilities in the question, not difficulties with the macro.
Member Author

### paultpearson commented Dec 4, 2015

 DOCUMENT(); loadMacros( "PGstandard.pl", "parserWordCompletion.pl", "parserMultiAnswer.pl", ); TEXT(beginproblem()); Context('Numeric'); $ans1 = WordCompletion( ["BASIC","Haskell","Perl","Python"], "Python" );$ans2 = WordCompletion( ["Perl","Python"], "Perl" ); $fac1 = WordCompletion( ["Perl","Python"], "Perl" );$fac2 = WordCompletion( ["Perl","Python"], "Python" ); $multians = MultiAnswer($fac1, $fac2)->with( singleResult => 0, checker => sub { my ($correct, $student,$self ) = @_; my ( $f1stu,$f2stu ) = @{$student}; my ($f1, $f2 ) = @{$correct}; if ( ($f1 ==$f1stu && $f2 ==$f2stu) || ($f1 ==$f2stu && $f2 ==$f1stu) ) { return [1,1]; } else { if ($f1 ==$f1stu || $f2 ==$f1stu) { return [1,0]; } elsif ($f1 ==$f2stu || $f2 ==$f2stu) { return [0,1]; } else { return [0,0]; } } } ); BEGIN_TEXT Enter ( \pi ) { ans_rule() } $PAR What programming language is named after a snake? {$ans1->ans_rule(50) } Your choices are: { $ans1->choices_text }.$PAR Enter ( x^2 ) { ans_rule() } $PAR What programming language is WeBWorK written in? {$ans2->menu() } $PAR Your choices are: {$ans2->choices_list } $PAR The two best programming languages are {$multians->ans_rule(20) } and { $multians->ans_rule(20) }. END_TEXT ANS( Compute("pi")->cmp ); ANS($ans1->cmp ); ANS( Compute("x^2")->cmp ); ANS( $ans2->cmp ); ANS($multians->cmp ); ENDDOCUMENT();
Member

### mgage commented Dec 5, 2015

 This works well on ordinary answers. It doesn't work well for me on multians. I keep getting error warnings about extra answer blanks. I think this is all bound up with determining the right names for answer blanks and answer evaluators -- which is a bit tricky in general and even more so for multians. I'll look at it again but you might want to some experiments yourself and make sure that it works for you..
Member Author

### paultpearson commented Dec 5, 2015

 The WordCompletion macro works with MultiAnswer on the Hope server running ww_version 2.8 & pg_version 2.8.1. When I push it to the MAA TestCourses server running ww_version develop & pg_version 2.11, however, I get errors just like you said. So, something has changed with MultiAnswer between version ~2.8 and version ~2.11, and I'll have to update the WordCompletion macro accordingly.
Member

### mgage commented Dec 5, 2015

 OK. Thanks for checking against versions of PG. I was actually using the develop branch when I checked your macro.
mentioned this pull request Apr 20, 2016