/r;
+}
+
+sub decode_question {
+ my ($choices_idx, $correct_idx) = answer_choices();
+ # generate a question type
+ my %type_hash = (0 => 1, 1 => 1, 2 => 1, 3 => 1);
+ my @types = ();
+ for (1..2) {my $cur; do {$cur = int(rand 4);} while($type_hash{$cur} == 0); push @types, $cur; $type_hash{$cur} = 0;};
+ my $question = "What is the " . $abbreviations[$types[1]] . " for " . $amino[$correct_idx]->[$types[0]] . "?";
+ my $answer = $amino[$correct_idx]->[$types[1]];
+ my @options = (); for(@$choices_idx) { push @options, $amino[$_]->[$types[1]] }
+ if (rand() < 0.3 && $types[1] != 3) {
+ return $question, $answer, [];
+ }
+ return $question, $answer, \@options;
+}
+
+sub properties_question {
+ my ($choices_idx, $correct_idx) = answer_choices();
+ my $question = "Property of the amino acid " . $amino[$correct_idx]->[int(rand 4)];
+ return $question, $amino[$correct_idx]->[4], \@properties;
+}
+
+
+sub construct_form {
+ my ($question, $answer, $options) = @_;
+ $answer = $answer;
+ $question = urldecode $question;
+ my $question_label = to_image $question;
+ print "";
+}
+
+if ($ENV{'REQUEST_METHOD'} =~ /POST/i) {
+ my $parameters = parse_post();
+ our $response = ($parameters->{'response'} // '');
+ our $answer = ($parameters->{'answer'} // 'wrong');
+ our $question = ($parameters->{'question'} // '');
+ our @options = split(',', $parameters->{'options'} // '');
+ # answer and response should have the same elements.
+ our $correct = check_equivalence $answer, $response;
+ construct_form($question, $answer, \@options);
+ if ($correct) {
+ print "Correct!
"; + } else { + print "Incorrect!
"; + } +} else { + if (int(rand(2)) == 0) { + construct_form(properties_question()); + } else { + construct_form(decode_question()); + } +} + + +print ""; +print ""; + +print "