Same result. Fewer lines


#1

These 2 codes give the same result. Is one wrong or just bad practise

01 print "What's your first name?"
02 first_name = gets.chomp.capitalize
03 print "What's your last name?"
05 last_name = gets.chomp.capitalize
06 print "Which city are you from?"
07 city_name = gets.chomp.capitalize
08 print "What is the county, abreviated?"
09 county_name = gets.chomp.upcase
10 puts "Your name is #{first_name} #{last_name}. You are from #{city_name} in #{county_name}"


01 print "What's your first name?"
02 first_name = gets.chomp
03 first_name2 = first_name.capitalize
04 first_name.capitalize!
05 print "What is your lastname?"
06 last_name = gets.chomp
07 last_name2 = last_name.capitalize
08 last_name.capitalize!
09 print "Which city are you from?"
10 city_name = gets.chomp
11 city_name2 = city_name.capitalize
12 city_name.capitalize!
13 print "What is the county, abreviated?"
14 county_name = gets.chomp
15 county_name2 = county_name.upcase
16 county_name.upcase!
17 puts "Your name is #{first_name2} #{last_name2}. You are from #{city_name2} in #{county_name2}"


#2

I agree, as we learned in one of the previous lessons we can call multiple methods on one object.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.