Quiz

Important

As of Version 1.1.0 this MDBook template now has the capability to embedded quizzes into markdown book, using:

  • https://github.com/cognitive-engineering-lab/mdbook-quiz/releases/tag/v0.3.10

First, create a quiz file. Quizzes are encoded as TOML files (see Quiz schema). For example

Code

# quizzes/rust-variables.toml
[[questions]]
type = "ShortAnswer"
prompt.prompt = "What is the keyword for declaring a variable in Rust?"
answer.answer = "let"
context = "For example, you can write: `let x = 1`"

Important

When running mdbook-quiz locally, or when you check the source code for the deployment each question will have anid field auto generated

and in the markdown file:

Code

And now, a _quiz_:

{{#<type> ./quizzes/rust-variables.toml}}}

Warning

Replace <type> with quiz

And now, a quiz:

Here is a multiple choice example:

Code

[[questions]]
type = "MultipleChoice"
prompt.prompt = "What does it mean if a variable `x` is immutable?"
prompt.distractors = [
  "`x` is stored in the immutable region of memory.",
  "After being defined, `x` can be changed at most once.",
  "You cannot create a reference to `x`."
]
answer.answer = "`x` cannot be changed after being assigned to a value."
context = """
Immutable means "not mutable", or not changeable.
"""

You can have more than one question per quiz, by stacking quizzes into one file <nameofquiz>.toml, the beauty is if you don't get them all correct you can revist the ones you got wrong.

Warning

Remember that question id is unique, so if you copy and paste repeated questions, remember to remove the id field

Copyright © 2025 • Created with ❤️ by CompEng0001

Page last updated: Thursday 26 June 2025 @ 13:53:04 | Commit: 77cc9bd