Created
April 18, 2022 19:38
-
-
Save caioertai/0bcbf6081951f4a9c83ee097e850f7c5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Define an array of horses names | |
# 0 1 2 3 4 | |
horse_names = ["Joel", "Andy", "Nadia", "Joey", "Filhinho Papai"] | |
# Print welcome and the horses names | |
puts "Welcome to the horse race" | |
puts "Here are the horses:" | |
horse_names.each_with_index do |name, index| | |
puts "#{index + 1}. #{name}" | |
end | |
# Ask the user to type the name of the horse they want to pick | |
puts "Which horse you want to bet on? (type below)" | |
user_bet_index = gets.chomp.to_i - 1 | |
user_bet = horse_names[user_bet_index] | |
puts "You're betting on #{user_bet}. Good luck to your horse!" | |
# Run the race 🐴 (by getting a sample from the horses array) | |
race_results = horse_names.shuffle | |
winner_name = race_results.first | |
10.times do | |
print "." | |
sleep 0.1 | |
end | |
puts " the results are in!" | |
race_results.each_with_index do |name, index| | |
puts "#{index + 1}. #{name}" | |
end | |
# Print the winner's name | |
puts "The winner is: #{winner_name}" | |
# Compare the bet with the winner | |
if winner_name == user_bet | |
puts "Congratulations! #{winner_name} won!" | |
else | |
puts "So sorry! Better luck next time!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment