Skip to content
Classroom

Multiple Choice

Answer type: choices

The student picks exactly one option from a list.

The minimum

$questions holds the options; $answer is the index of the correct one, counting from zero.

Common Control:

$questions = array("Increasing", "Decreasing", "Constant")
$answer = 0

No [multiplechoice] section

Earlier versions of this page showed a bracketed section with answer = A; and options = …. There are no bracketed sections, the type is chosen in the editor, and the options list is $questions — an array. If it is missing or not an array the question fails with Eeek! $questions is not defined or needs to be an array.

Options

Variable Effect
$questions the list of options — required, must be an array
$answer zero-based index of the correct option — required
$noshuffle which options stay put; see below
$displayformat layout of the option list
$partialcredit partial credit for specific wrong options, as a flat list of index/credit pairs — array(2, 0.5) gives half credit for the option at index 2 (the third)

$noshuffle

Options are shuffled per student by default, so the correct answer is not always in the same place.

Value Effect
"none" (default) shuffle everything
"all" shuffle nothing — keep the order given
"last" shuffle all but the last option
"last2", "last3", … shuffle all but the last n

"last" is what you want for a trailing "None of the above" — shuffling it into the middle makes it nonsense.

$questions = array("12", "16", "20", "None of the above")
$answer = 1
$noshuffle = "last"

$displayformat

"vert" is the default — one option per line. Use it unless the options are very short.

Shuffling and feedback together

Because the engine shuffles, the index you store is the index before shuffling; you do not need to compensate. The same holds for per-option feedback. Keep the feedback in an array parallel to $questions and do not reorder either array. The student's choice is recorded as its original (unshuffled) index, so getfeedbacktxt finds the matching message — see Feedback Macros. Do not shuffle $questions yourself with jointshuffle. It moves the options but leaves $answer pointing at the old position, so a different option is graded correct.

Example

Common Control — setup:

$m = nonzerorand(-6, 6)
$b = nonzerorand(-9, 9)
$eq = makexxpretty("$m x + $b")
$questions = array("increasing", "decreasing", "constant")
$noshuffle = "all"
$correct = ifthen($m > 0, 0, 1)

Question Text:

<p>Is the line `y = $eq` increasing, decreasing, or constant?</p>

Common Control, continued — answer and options:

$answer = $correct

See Also