Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Guess-the-number/Elixir/guess-the-number.elixir
Normal file
21
Task/Guess-the-number/Elixir/guess-the-number.elixir
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
defmodule GuessingGame do
|
||||
def play do
|
||||
play(Enum.random(1..10))
|
||||
end
|
||||
|
||||
defp play(number) do
|
||||
guess = Integer.parse(IO.gets "Guess a number (1-10): ")
|
||||
case guess do
|
||||
{^number, _} ->
|
||||
IO.puts "Well guessed!"
|
||||
{n, _} when n in 1..10 ->
|
||||
IO.puts "That's not it."
|
||||
play(number)
|
||||
_ ->
|
||||
IO.puts "Guess not in valid range."
|
||||
play(number)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
GuessingGame.play
|
||||
Loading…
Add table
Add a link
Reference in a new issue