In Assigning badges to pages we looked at how to create a panel showing which badges have been earned, or could be earned, on a page. To be able to earn a badge you have to demonstrate some kind of knowledge. This will be demonstrated through being able to answer questions assigned to each badge.

Creating questions and answers

Two more concepts are needed here;
  • A question is  multiple choice (single or multiple answer), numeric or textual. The type, title and answers are included in the question object, and it can randomize the order in which the multiple choice options are given. It has a unique ID that can be used to identify this question
  • A question Set is a series of questions that go together. A question set would be assigned to a badge. The questions can be randomized within a question set, and a minimum %age of correct answers that qualify as a pass can also be provided. Each question set has a unique ID.
These are stored in the same scriptDB as the badge information. The below code does not work anymore due to ScriptDb being now deprecated. I am leaving it here so you see the arguments. It was displaying the questions set information using ScriptDb.

and some question information…

Here are the constructors for a question and a questionset

And here is how to make and store some questions and questionsets (but a better method is to construct your database from a spreadsheet (see Creating badge environment from a spreadsheet
For more about badges see Badges