Checkbox

Select answers from given options.

Simple example

This simple checkbox example only requires writing a question.html file. This implementation only creates one unique version of the question, with the same set of parameters and answers. The only level of randomization comes from the order in which the answers are displayed.

<pl-question-panel>
<p>
Select the animals that belong to the <strong>bird</strong> group?
</p>
</pl-question-panel>
<pl-checkbox answers-name="select" hide-letter-keys="true" >
<pl-answer correct="true"> Eagle </pl-answer>
<pl-answer correct="false"> Tilapia </pl-answer>
<pl-answer correct="true"> Crow </pl-answer>
<pl-answer correct="false"> Crocodile </pl-answer>
<pl-answer correct="false"> Zebra </pl-answer>
<pl-answer correct="false"> Snake </pl-answer>
</pl-checkbox>

Complex example

We can add variation to this example by adding randomization to the group parameter.

The modified question.html file that supports the randomization is:

<pl-question-panel>
<p>
Select the animals that belong to the <strong>{{params.group}}</strong> group?
</p>
</pl-question-panel>
<pl-checkbox answers-name="select" hide-letter-keys="true" >
<pl-answer correct={{params.ans0}}> {{params.text0}} </pl-answer>
<pl-answer correct={{params.ans1}}> {{params.text1}} </pl-answer>
<pl-answer correct={{params.ans2}}> {{params.text2}} </pl-answer>
<pl-answer correct={{params.ans3}}> {{params.text3}} </pl-answer>
<pl-answer correct={{params.ans4}}> {{params.text4}} </pl-answer>
<pl-answer correct={{params.ans5}}> {{params.text5}} </pl-answer>
</pl-checkbox>

To generate the parameters, we can use the following Python code in server.py:

import random
def generate(data):
# List of animals in each group
# More animals can be added here for increased variation
animals = {"mammal": ["Bear", "Monkey", "Dog", "Cheetah", "Koala", "Zebra"],
"bird": ["Dove", "Chicken", "Duck", "Sparrow", "Crow", "Eagle"],
"fish": ["Salmon", "Tilapia", "Tuna", "Yellowtail", "Carp", "Cod"],
"reptile": ["Lizard", "Snake", "Turtle", "Crocodile", "Gecko", "Chameleon"]}
# List with all the groups
all_groups = list(animals.keys())
# Select one of the groups as the correct answer
group = random.choice(all_groups)
data["params"]["group"] = group
# List containing the remaining groups (incorrect answer)
remaining_groups = all_groups.copy()
remaining_groups.remove(group)
# Get "n" animals from the "true" group
n = random.choice([2,3])
true_ans = random.sample(animals[group], n)
# Storing the correct answers in the data dictionary
for i in range(n):
data["params"]["text"+str(i)] = true_ans[i]
data["params"]["ans"+str(i)] = "true"
# Get "6-n" from the "false" group
all_remaining_animals = []
for g in remaining_groups:
all_remaining_animals += animals[g]
false_ans = random.sample(all_remaining_animals, 6-n)
# Storing the incorrect answers in the data dictionary
for i in range(6-n):
data["params"]["text"+str(n+i)] = false_ans[i]
data["params"]["ans"+str(n+i)] = "false"
return

Here's one instance of this fully randomized question: