Skip to content

Instantly share code, notes, and snippets.

@troyleach
Created January 12, 2015 05:46
Show Gist options
  • Select an option

  • Save troyleach/5844a6477caf6cf78f77 to your computer and use it in GitHub Desktop.

Select an option

Save troyleach/5844a6477caf6cf78f77 to your computer and use it in GitHub Desktop.
screencast #8 guessing game
my_number = rand(50)
num_guesses = 0
loop {
print "choose a number between 1 and 6: "
guess = gets.chomp.to_i
num_guesses += 1
puts "#{guess} is to low" if guess < my_number
puts "#{guess} is to high" if guess > my_number
break if guess == my_number
}
puts "you won #{my_number} is the right number!"
puts "your number of guess was #{num_guesses}"
#if guess > my_number
# puts "sorry #{guess} is to high"
#elsif guess < my_number
# puts "sorry #{guess} to low"
#else
# puts "WOW.... #{guess} THAT MY NUMBER"
#end
if @guess == my_number
return "true"
else
return "false"
end
#while guess != my_number
# case guess
# when guess > my_number
# puts "sorry to high"
# print prompt
# when guess < my_number
# puts "sorry to low"
# print prompt
# else
# puts "WOW.. THAT'S RIGHT"
# break
# end
#end
#THIS WORKS
#my_number = rand(10)
#guess = nil
#
#until guess == my_number
# puts "Please guess again"
# guess = gets.chomp.to_i
#end
@markeban

Copy link
Copy Markdown

Amazing! I take it you mean "choose a number between 1 and 50"?

@troyleach

Copy link
Copy Markdown
Author

I did... sorry - thanks!!!

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