Skip to content

Instantly share code, notes, and snippets.

@lcoullet
Created June 18, 2018 13:31
Show Gist options
  • Save lcoullet/f24ba7fc74b9107571bb994f3a65e236 to your computer and use it in GitHub Desktop.
Save lcoullet/f24ba7fc74b9107571bb994f3a65e236 to your computer and use it in GitHub Desktop.
The Guessing Game (Elixir 1.6) - ep1 challenge
defmodule Greeter do
def greet do
answer = IO.gets("Hi, nice to meet you, what's your name ?\n")
case Regex.match?(~r/^[a-z, A-Z ,.'-]+$/, answer) do
true ->
greet(answer)
false ->
IO.puts("Please enter a valid name.\n")
greet()
end
end
defp greet(name) do
case String.downcase(String.trim(name)) do
"ludovic" -> IO.puts("Ludovic, what a wonderful name!")
_ -> IO.puts("Hi #{name}!\n")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment