...

/

Trying Out the Quiz Manager

Trying Out the Quiz Manager

Now let’s take our quiz manager for a spin.

Executing the quiz manager

In this section, we’re going to put the quiz through its paces. Part of writing good code is building the infrastructure to support learning and exploration. We’re going to create a trivial module to let new users and developers alike explore our features in the console.

Creating a quiz

Let’s create a simple math quiz with a mastery of two and a template for single-digit addition. We’ll create a new file, lib/mastery/examples/math.ex, and fill it in. None of this code will be new to us:

Press + to interact
defmodule Mastery.Examples.Math do alias Mastery.Core.Quiz
def template_fields() do
[
name: :single_digit_addition,
category: :addition,
instructions: "Add the numbers",
raw: "<%= @left %> + <%= @right %>",
generators: addition_generators(),
checker: &addition_checker/2
]
end
def addition_checker(substitutions, answer) do
left = Keyword.fetch!(substitutions, :left)
right = Keyword.fetch!(substitutions, :right) to_string(left + right) == String.trim(answer)
end
def addition_generators() do
%{left: Enum.to_list(0..9),
right: Enum.to_list(0..9)}
end
def quiz_fields() do
%{ mastery: 2, title: :simple_addition}
end
def quiz() do quiz_fields()
|> Quiz.new
|> Quiz.add_template(template_fields())
end
end
  • We have separate functions for ...