first_name = gets.chomp
first_name.capitalize!
print "What's your last name?"
last_name = gets.chomp
last_name.capitalize!
print "What city are you from?"
city = gets.chomp
city.capitalize!
print "What state or province are you from?"
state = gets.chomp
state.upcase!
puts "Your name is #{first_name} #{last_name} and you're from #{city}, #{state}!"
#=============================================================
- First we introduce one new method,
capitalize, here. It capitalizes the first letter of a string and makes the rest of the letters lower case. We assign the result toanswer2 - The next line might look a little strange, we don't assign the result of
capitalizeto a variable. Instead you might notice the!at the end ofcapitalize. This modifies the value contained within the variableansweritself. The next time you use the variableansweryou will get the results ofanswer.capitalize ===============================================================================print " what is your first name ? "first_name = gets.chompfirst_name = first_name.capitalize!print " what is your last name ? "last_name = gets.chomplast_name = last_name.capitalize!print "what is your city ? "city = gets.chompcity = city.capitalize!print "what is your state ? "state = gets.chompstate = state.upcase!print " #{first_name} #{last_name} #{city} #{state} "=====================================================================
No comments:
Post a Comment