Skip to content

Instantly share code, notes, and snippets.

@caioertai
Created April 18, 2022 20:37
Show Gist options
  • Save caioertai/14072cec3ccc72b7e67c970b0d142dff to your computer and use it in GitHub Desktop.
Save caioertai/14072cec3ccc72b7e67c970b0d142dff to your computer and use it in GitHub Desktop.
horse_names = ["Joel", "Andy", "Nadia", "Joey", "Filhinho Papai"]
puts "Welcome to the horse race"
# [2BF] define a money variable starting at
loop do
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)"
# [2BF] Print the amount of money the user has
user_bet_index = gets.chomp.to_i - 1
user_bet = horse_names[user_bet_index]
# [2BF] Print a message about the amount being bet
# [2BF] Decrement the bet on the money variable (-=)
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!"
# [2BF] Print a message about the winnings
# [2BF] Increment the winnings on the money variable (+=)
else
puts "So sorry! Better luck next time!"
end
# [1LF] Ask if user wants to continue (save the answer in a variable)
# [1LF] break if user does not want to continue (break)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment