Answer and answer2 are a bit confusing for beginners


#1

Heya,

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.


#2

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!


#3

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
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 are you from?"
state = gets.chomp
state.upcase!

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?


#4

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


#5

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


#6