exercism/elixir/guessing-game/lib/guessing_game.ex

9 lines
470 B
Elixir
Raw Normal View History

2023-12-17 06:14:53 +00:00
defmodule GuessingGame do
def compare(secret_number, guess \\ :no_guess)
def compare(_secret_number, :no_guess), do: "Make a guess"
def compare(secret_number, guess) when secret_number == guess, do: "Correct"
def compare(secret_number, guess) when abs(secret_number - guess) == 1, do: "So close"
def compare(secret_number, guess) when guess > secret_number, do: "Too high"
def compare(secret_number, guess) when guess < secret_number, do: "Too low"
end