They don't know where to start. To help new players out, you decided to write a small program that will guide them through the process.
Implement the RPG.CharacterSheet.welcome/0 function. It should print a welcome message, and return :ok.
Implement the RPG.CharacterSheet.ask_name/0 function. It should print a question, wait for an answer, and return the answer without leading and trailing whitespace.
Implement the RPG.CharacterSheet.ask_class/0 function. It should print a question, wait for an answer, and return the answer without leading and trailing whitespace.
Implement the RPG.CharacterSheet.ask_level/0 function. It should print a question, wait for an answer, and return the answer as an integer.
Implement the RPG.CharacterSheet.run/0 function. It should welcome the new player, ask for the character's name, class, and level, and return the character sheet as a map. It should also print the map with the label "Your character".
https://exercism.org/tracks/elixir/exercises/rpg-character-sheet
defmodule RPG.CharacterSheet do
@moduledoc """
IO related
"""
@doc """
practice with IO module
"""
@spec welcome() :: :ok
def welcome(), do: IO.puts("Welcome! Let's fill out your character sheet together.")
@doc """
IO.gets practice
"""
@spec ask_name() :: IO.chardata()
def ask_name(), do: IO.gets("What is your character's name?\n") |> String.trim()
@spec ask_class() :: IO.chardata()
def ask_class(), do: IO.gets("What is your character's class?\n") |> String.trim()
def ask_level(),
do: IO.gets("What is your character's level?\n") |> String.trim() |> String.to_integer()
@spec run() :: IO.chardata()
def run() do
welcome()
name = ask_name()
class = ask_class()
level = ask_level()
IO.inspect(%{class: class, level: level, name: name}, label: "Your character")
end
end