Last active
July 11, 2017 16:08
-
-
Save luizfonseca/b5332379e5df85e242e0a0d5b75e5763 to your computer and use it in GitHub Desktop.
[Reboot] Horse races
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
# 1) print "Welcome to the Horse Race of Le Wagon" | |
# 2) Create a List of horses? DONE | |
# 3) Show the list of horses | |
# 4) Ask the user: "On which horse do you want to bet on?" | |
# 5) Ask the user: "How much do you want to bet?" | |
# 6) Place the bet | |
# 7) Run the race METHOD | |
# 8) Display the result of the race: "Winner/Loser" | |
# 9) Display the result of the bet | |
# 10) Want to bet again? | |
puts "###### HORSE RACE PROGRAM #######\n\n\n" | |
puts "Welcome to the Horse Race of Le Wagon" | |
horses = ["Colt", "Bolt", "Jolt", "Miguel"] | |
puts "The horse of today are: \n\n" | |
horses.each_with_index do |horse, index| | |
puts "#{index + 1} - #{horse}" | |
end | |
puts "\nOn which horse do you want to bet on (type the number)?\n" | |
user_horse = gets.chomp.to_i | |
puts "\nHow much do you want to bet?" | |
bet_placed = gets.chomp.to_f | |
# Run the race | |
# The SAMPLE method on an array, returns one value of the array. | |
# So if the array is an array of many elements, it will return ONE of the elements right away | |
winner = horses.sample # Winner!!! | |
# Updating the value of user_horse with the VALUE of the Horse in the array | |
# Remember: in this line i am just overrwriting a previous variable with another value | |
# and HORSES[INDEX_NUMBER] evaluates to a value from the array, gotcha? | |
user_horse = horses[user_horse - 1] | |
puts "The winner was #{winner}." | |
if user_horse == winner | |
puts "The horse won the race! Congratulations" | |
else | |
puts "The horse didnt win. You bet were on #{user_horse} and lost #{bet_placed} " | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment