Created
June 18, 2018 13:31
-
-
Save lcoullet/f24ba7fc74b9107571bb994f3a65e236 to your computer and use it in GitHub Desktop.
The Guessing Game (Elixir 1.6) - ep1 challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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