Skip to content

Instantly share code, notes, and snippets.

@jules2689
Last active August 29, 2015 14:01
Show Gist options
  • Save jules2689/c79d8cda00c2ae4c4a47 to your computer and use it in GitHub Desktop.
Save jules2689/c79d8cda00c2ae4c4a47 to your computer and use it in GitHub Desktop.
Code For Kids Ruby Script
puts 'Put the lower number'
lowest = gets.to_i
puts 'Put the higher number'
highest = gets.to_i
puts "Choosing a random number in the range " + lowest.to_s + " and " + highest.to_s
our_number = (lowest..highest).to_a.choice
guess_counter = 0
found = false
while not(found)
puts "Enter your guess!"
guess = gets.to_i
guess_counter = guess_counter + 1
if guess < our_number
puts "Nice try! The right number is higher."
elsif guess > our_number
puts "Nice try! The right number is lower."
else
puts "GREAT JOB! The number was " + guess.to_s + " it took you " + guess_counter.to_s + " guesses to figure that out!"
found = true
end
end
puts "Thanks for playing!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment