Trying Out the Quiz Manager
Now let’s take our quiz manager for a spin.
We'll cover the following...
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.Quizdef template_fields() do[name: :single_digit_addition,category: :addition,instructions: "Add the numbers",raw: "<%= @left %> + <%= @right %>",generators: addition_generators(),checker: &addition_checker/2]enddef addition_checker(substitutions, answer) doleft = Keyword.fetch!(substitutions, :left)right = Keyword.fetch!(substitutions, :right) to_string(left + right) == String.trim(answer)enddef addition_generators() do%{left: Enum.to_list(0..9),right: Enum.to_list(0..9)}enddef quiz_fields() do%{ mastery: 2, title: :simple_addition}enddef quiz() do quiz_fields()|> Quiz.new|> Quiz.add_template(template_fields())endend
-
We have separate functions for ...