Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Last active April 15, 2020 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc00ke/091ffc3793c6a729427b68e79e6850de to your computer and use it in GitHub Desktop.
Save jc00ke/091ffc3793c6a729427b68e79e6850de to your computer and use it in GitHub Desktop.
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