QuizQuestions

QuizQuestions allows the inclusion of self-grading quiz questions within a Documenter, Weave, quarto, or Pluto HTML page.

Basics

The basic idea is:

  • load the package:
using QuizQuestions
  • create a question with Julia code:
choices = ["one", "``2``", raw"``\sqrt{9}``"]
question = "Which is largest?"
answer = 3
radioq(choices, answer; label=question, hint="A hint")
  • repeat as desired.

The quizzes are written in markdown with the questions in Julia blocks. The above code cells would be enclosed in triple-backtick blocks and would typically have their contents hidden from the user. How this is done varies between Documenter, Weave, quarto, and Pluto. The examples directory shows examples of each.


For each question:

  • The show method of the object for the text/html mime type inserts the necessary HTML and JavaScript code to show the input widget and grading logic.

  • the optional hint argument allows a text-only hint available to the user on hover.

  • The optional label argument is used to flag the question.

  • The optional explanation argument is used to give feedback to the user in case there is an incorrect answer given.

For example, the question can be asked in the body of the document (the position of any hint will be different):

answer = sqrt(2)
tol = 1e-3
numericq(answer, tol,
    label=raw"What is ``\sqrt{2}``?",
	hint="you need to be within 1/1000")

Examples of question types

Choice questions (one from many)

The radioq question was shown above.

The buttonq question is alternative to radio buttons where the correct answer is shown after the first choice. If this choice is wrong, the explanation is shown along with the correct answer.

buttonq(["``1 + 1``", "``2+2``", "``-1 + -1``"], 1;
    label = "Which adds to ``2``?",
	explanation="Add 'em up")

Multiple choices (one or more from many)

A multiple choice question (one or more from many) can be constructed with multiq:

choices =[
	"Four score and seven years ago",
	"Lorum ipsum",
	"The quick brown fox jumped over the lazy dog",
	"One and one and one makes three"
]
ans = (1, 4)
multiq(choices, ans,
    label="Select the sentences with numbers (one or more)")

The multibuttonq question is similar, but it uses a "done" button to initiate the grading. This allows for answers with $0$, $1$, or more correct answers.

choices =[
	"Four score and seven years ago",
	"Lorum ipsum",
	"The quick brown fox jumped over the lazy dog",
	"One and one and one makes three"
]
ans = (1, 4)
multibuttonq(choices, ans,
    label="Select the sentences with numbers (one or more)")

Numeric answers

Questions with numeric answers use numericq. The question is graded when the input widget loses focus.

answer = 1 + 1
numericq(answer;
    label="``1 + 1``?",
	hint="Do the math")

Numeric questions can have an absolute tolerance set to allow for rounding.

Text response

A question graded by a regular expression can be asked with stringq. The question is graded when the input widget loses focus.

stringq(r"^Washington"; label="Who was the first US president?",
        placeholder="last name")

Matching

A question involving matching can be asked with matchq.

questions = ("Select a Volvo", "Select a Mercedes", "Select an Audi")
choices = ("XC90", "A4", "GLE 350", "X1") # may be more than questions
answer = (1,3,2) # indices of choices that match correct answer for each question
matchq(questions, choices, answer;
    label="For each question, select the correct answer.")

The above shows that the number of choices need not match the number of questions. When they do, a dictionary can be used to specify the choices and the answers will be computed:

d = Dict("Select a Volvo" => "XC90", "Select a Mercedes" => "GLE 350",
         "Select an Audi" => "A4")
matchq(d, label="Match the manufacture with a model")

Fill-in-the-blank questions

Fill-in-the blank questions can be asked with fillblankq. Answers can be gathered and graded in different manners.

question = "The quick brown fox jumped over the ____ dog"
fillblankq(question, ("lazy", "brown", "sleeping"), 1)
The quick brown fox jumped over the dog

(like stringq)

question = "The quick brown fox jumped over the ____ dog"
fillblankq(question, r"^lazy$")
The quick brown fox jumped over the dog

(like numericq)

question = "____ `` + 2  = 4``"
fillblankq(question, 2)
\(+ 2 = 4\)

Select from an image question

The hotspotq shows an image, specified by a file, and grades an answer correct if a mouse click is in a specified rectangular region. The region is given in terms of (xmin,xmax) and (ymin, ymax) as if the entire region was in $[0,1] \times [0,1]$, though the correct_answer argument allows for more complicated regions.

using Plots
p1 = plot(x -> x^2, axis=nothing, legend=false)
p2 = plot(x -> x^3, axis=nothing, legend=false)
p3 = plot(x -> -x^2, axis=nothing, legend=false)
p4 = plot(x -> -x^3, axis=nothing, legend=false)
l = @layout [a b; c d]
p = plot(p1, p2, p3, p4, layout=l)
imgfile = tempname() * ".png"
savefig(p, imgfile)
hotspotq(imgfile, (0,1/2), (0, 1/2),
    label="What best matches the graph of ``f(x) = -x^4``?")

The PlotlyLight package provides a very lightweight interface for producing JavaScript based graphs with the plotly.js library. The plotlylight type allows questions involving an (x,y) selection from a graph ((x,y) is a point on a graph).

Note

The plotlylight question type does not work with Documenter.

Reference

The available question types are listed below. If others are desirable, open an issue on the GitHub repository.

Missing docstring.

Missing docstring for radioq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for buttonq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for yesnoq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for booleanq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for multiq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for multibuttonq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for matchq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for numericq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for stringq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for fillblankq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for hotspotq. Check Documenter's build log for details.

Missing docstring.

Missing docstring for plotlylightq. Check Documenter's build log for details.