Skip to content

Instantly share code, notes, and snippets.

@mjhea0
Last active December 16, 2015 15:59
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 mjhea0/5459953 to your computer and use it in GitHub Desktop.
Save mjhea0/5459953 to your computer and use it in GitHub Desktop.
just a basic guessing game - cheers!
class GuessingGame
def initialize(answer)
@answer = answer
end
def guess(guess)
@guess = guess
if guess > @answer
puts "high"
return :high
elsif guess < @answer
puts "low"
return :low
elsif guess == @answer
puts "correct"
return :correct
end
end
def solved?
@guess == @answer
if @guess == @answer
puts "yes"
else
puts "no"
end
end
end
#game = GuessingGame.new(10)
#game.solved?
#game.guess(5)
#game.guess(20)
#game.solved?
#game.guess(10)
#game.solved?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment