Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created April 9, 2019 16:31
Show Gist options
  • Save krokrob/a01e6112b274983fad85746b545089d9 to your computer and use it in GitHub Desktop.
Save krokrob/a01e6112b274983fad85746b545089d9 to your computer and use it in GitHub Desktop.
# compute computer choice
random_price = (1..100).to_a.sample
guess_price = 0 # initialization
until guess_price == random_price
# ask user input and put into an integer
puts " What price is the object?"
guess_price = gets.chomp.to_i
# compare the 2 entries
if guess_price == random_price
puts "You win"
elsif guess_price > random_price
puts "it's less"
else
puts "it's more"
end
end
# tell user if it's more or less or if win
# repeat the process until the user wins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment