Last active
August 29, 2015 14:01
-
-
Save jules2689/c79d8cda00c2ae4c4a47 to your computer and use it in GitHub Desktop.
Code For Kids Ruby Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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