Answer and answer2 are a bit confusing for beginners



So I know that this is just an example to show beginners "how it works" but it's confusing as ■■■■ and could probably teach them something wrong.
You only need 1 variable that you can then modify, not 2. In this case answer gets a userinput, then gets an answer2 which capitalizes it and then writes it back to answer, even tho we'd never have needed answer2.

I'm only mentioning this because it kind of confused me and I nearly thought that this would be the way to archive this, even tho we only need 1 variable at all times.


Thanks for that!
I had thought exactly that and did indeed as a beginner find it confusing.
Am I right in thinking that modifying that segment of code as follows would produce the same result?

print "This is my question"
answer = gets.chomp.capitalize!


I am a bit confused about this as well. Why do we need to assign it to answer 2?

I did:

print "What's your first name?"
first_name = gets.chomp

print "What's your last name?"
last_name = gets.chomp

print "What city are you from?"
city = gets.chomp

print "What state are you from?"
state = gets.chomp

puts "Your name is #{first_name} #{last_name}. You are from #{city} in #{state}."

It seemed to work as it printed the words with the first letter capitalised. Is this ok?


You are not required to do that, it was just shown as something that you could do, if you wanted to.


Hi I did this and it worked ok so I think there is no problem.
On the other hand I think you could have done gets.chomp.capitalize with the same result