-
-
Save rickhull/0859a68ef88cdd100a4e4a9d6cb433d9 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
prices = { | |
"tennis ball" => 4.99, | |
"beach ball" => 12.99, | |
"giraffe" => 93.86, | |
} | |
print "What is your name? " | |
name = gets.chomp | |
puts "Alright #{name} what would you like to buy today? | |
We currently have #{prices.keys.join(', ')}." | |
prices.each { |name, price| | |
puts "The #{name} is #{price}" | |
} | |
balance = 120 | |
puts "Your balance is #{balance}" | |
print "What would you like to purchase? >" | |
purchase = gets.chomp | |
if prices.key?(purchase) | |
price = prices[purchase] | |
balance -= price | |
puts "Congratulations, you bought a #{purchase} for #{price}" | |
puts "Your new balance is #{balance}" | |
else | |
puts "Sorry, we don't have #{purchase}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment