Last active
April 15, 2020 23:52
-
-
Save jc00ke/091ffc3793c6a729427b68e79e6850de to your computer and use it in GitHub Desktop.
This file contains 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
def answer_question(%Game{current_question: current_question} = game, guess, user_name) | |
when is_binary(guess) do | |
game | |
|> Response.new(guess, user_name) | |
|> answer_question(game, user_name) | |
end | |
defp answer_question(%Response{correct: true} = response, game, user_name) do | |
game = | |
game | |
|> increase_score_for_user(user_name) | |
|> check_for_winning_user(user_name) | |
|> select_question() | |
{:ok, game} | |
end | |
defp answer_question(%Response{correct: false}, _game, _user_name) do | |
{:error, :incorrect} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment