Exercises from Chapter 5
Full Name Greeting
How you could do it:
puts 'What is your first name?' |
f_name = gets.chomp |
puts 'What is your middle name?' |
m_name = gets.chomp |
puts 'What is your last name?' |
l_name = gets.chomp |
full_name = f_name + ' ' + m_name + ' ' + l_name |
puts 'Hello, ' + full_name + '!' |
<= | What is your first name? |
=> | Sam |
<= | What is your middle name? |
=> | I |
<= | What is your last name? |
=> | Am |
<= | Hello, Sam I Am! |
How I would do it:
puts "What's your first name?" |
f_name = gets.chomp |
puts "What's your middle name?" |
m_name = gets.chomp |
puts "What's your last name?" |
l_name = gets.chomp |
puts "Chris Pine is cooler than you, #{f_name} #{m_name} #{l_name}." |
<= | What's your first name? |
=> | Marvin |
<= | What's your middle name? |
=> | K. |
<= ... |
Get Learn to Program, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.