Newbie puts problem

I’m running a simple “What is your name program” . The only thing that’s not working is the last puts. I need to do : “puts Hello, first name, last name”. I’ve rewrote this as many different ways as i can, but puts always displays: Hello first name
last name.
Why won’t it display all on one line? All my other puts statements display just fine.
This is my code: puts “Hello” “#{name1}” + “#{name2}”

puts "Hello #{name1} #{name2}"

|### Lawrence C. Mellen <[email protected]>|1:22 PM (7 minutes ago)||

|
| — | — | — |
|to hey

|

Thanks for the reply, but it’s not still not working:

code:

puts “What is your first name?”

name1 = gets

puts “What is your last name?”

name2 = gets

puts “Hello #{name1} #{name2}”

response:

What is your first name?

Donald

What is your last name?

Trump

Hello Donald

Trump

Hi @tofif,

There reason is that gets method including a line break, so you need chomp to remove it. This will make your code to looks like:

puts "What is your first name?"

name1 = gets.chomp

puts "What is your last name?"

name2 = gets.chomp

puts "Hello #{name1} #{name2}"

1 Like

Thanks Maniac,
I kept thinking the problem was in the 5th line. Now I now better! Thanks again!
I

You’re welcome! :slight_smile: