** (UndefinedFunctionError) function Mastery.Examples.Math.quiz_fields/0 is undefined (module Mastery.Examples.Math is not available) Mastery.Examples.Math.quiz_fields()

Hi,

I am getting this error -

** (UndefinedFunctionError) function Mastery.Examples.Math.quiz_fields/0 is undefined (module Mastery.Examples.Math is not available)
    Mastery.Examples.Math.quiz_fields()

I am not sure why I am getting this error since I did define this function.

lib/mastery.examples/math.ex:

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

What am I doing wrong?

Where are you getting the error? If in a test suite, make sure the test module name ends in Test. Sometimes I forget that and accidentally redefine the module I’m testing.

If iex, make sure it’s started like: iex -S mix

1 Like

Thank you very much for your answer!

Just after I posted this question (and after a descent time of looking for an answer), I found out that I was running ‘iex -S mix’ from a wrong module…

Best wishes!

1 Like