Skip to content

Instantly share code, notes, and snippets.

@caioertai
Created April 18, 2022 20:54
Show Gist options
  • Save caioertai/02ee10d91aa4c06292ff0dc58e6e753d to your computer and use it in GitHub Desktop.
Save caioertai/02ee10d91aa4c06292ff0dc58e6e753d to your computer and use it in GitHub Desktop.
horse_names = ["Joel", "Andy", "Nadia", "Joey", "Filhinho Papai"]
puts "Welcome to the horse race"
balance = 100
loop do
puts "-----=======-----"
puts "Here are the horses:"
horse_names.each_with_index do |name, index|
puts "#{index + 1}. #{name}"
end
puts "Which horse you want to bet on? (type below)"
puts "You currently have $#{balance}"
user_bet_index = gets.chomp.to_i - 1
user_bet = horse_names[user_bet_index]
balance -= 10
puts "You now have $#{balance}"
puts "You're betting on #{user_bet}. Good luck to your horse!"
race_results = horse_names.shuffle
winner_name = race_results.first
puts " the results are in!"
race_results.each_with_index do |name, index|
puts "#{index + 1}. #{name}"
end
puts "The winner is: #{winner_name}"
if winner_name == user_bet
puts "Congratulations! #{winner_name} won!"
puts "You just won $50"
balance += 50
else
puts "So sorry! Better luck next time!"
end
puts "-----=====-----"
if balance < 10
puts "Get lost!, you're out of money."
break
end
puts "Do you want to bet again? (y/n)"
puts "You currently have $#{balance}"
user_answer = gets.chomp
break if user_answer == "n"
end
puts "See you again another day!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment