Skip to content

Instantly share code, notes, and snippets.

@niieq
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save niieq/c31bcae8ba20dd75181b to your computer and use it in GitHub Desktop.

Select an option

Save niieq/c31bcae8ba20dd75181b to your computer and use it in GitHub Desktop.

Disappointed Elixir Guesser Game Developer

So as part of my journey learning elixir, i decided to write a small guessing game in elixir.

Decided to do this to understand and experiment with elixir because the book seems long for me.

But i kept making simple mistakes and complex ones. I got my head around the simple ones when i go back to the book and do a little reading but this complex ones still keep hitting me strong in the head.

It has been two weeks since i decided to write a blog post concerning a working guexxir(Name of my elixir guesser game).

Ok so now i am actually writing the post but my game is still not working. So this is my code structure. Help me fix it.

defmodule GuesElixir do
	def welcome_player do
		IO.puts String.duplicate("*", 80)
		IO.puts "Howdy! Let's GUEZZ A NAME"
		IO.puts String.duplicate("*", 80)
	end

	def checkguess(""), do: "Massa Massa! i beg enter something"

	def checkguess(n) do
		guesses = ["abigail","ade", "nii", "equity","cecilia"]
		if n in guesses do
			IO.puts "HAAY!!! you guessed right. i really like #{n} o "
		else
			IO.puts "Sorry u know nothing about my life"
		end
	end

	def enter_game_loop do
		welcome_player()
		urguess = IO.gets("What will be the name of my next best friend? ")
		better_guess = String.lstrip(urguess, ?\n)
		IO.puts "Ok so u guessed #{better_guess} , well lets see ......"
		checkguess(urguess)
	end

end
@rpip

rpip commented Sep 30, 2014

Copy link
Copy Markdown

Nice try. I like how you used pattern matching for the checkguess method

  1. I can't see the loop in the enter_game_loop method
  2. Reformat the post and highlight the syntax using Github's Markdown language highlight rule
  3. What do you think about using Mix to generate the project structure? I think this could also help you learn to use Mix and also understand the standard Elixir application structure.
  4. Also, please try to stick to standard, formal English language when writing technical posts.

@niieq

niieq commented Sep 30, 2014

Copy link
Copy Markdown
Author

Ok i will do all you have said. Thanks

@niieq

niieq commented Feb 8, 2015

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment