Get trouble with .capitalize!


#1



https://www.codecademy.com/courses/ruby-beginner-en-MxXx5/0/6?curriculum_id=5059f8619189a5000201fbcb#


The variables inputs still do not want to capitalize & uppercase. Have a look at the screenshot! Oh.. I can't upload the image IDK why.


print "What's your first name?"
first_name = gets.chomp
first_name2 = first_name.capitalize
first_name.capitalize!
print "What's your last name?"
last_name = gets.chomp
last_name2 =last_name.capitalize
last_name.capitalize!
print "What's your city?"
city = gets.chomp
city2 = city.capitalize
city.capitalize!
print "What's your state?"
state = gets.chomp
state2 = state.upcase
state.upcase!
print "Hello, Your name is #{first_name} #{last_name} and you are from #{city} and a stupid #{state}n and I am Showdown and you are done!"


#2

Hi this part

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

you saved the input(of the first print) here

first_name = gets.chomp

then you saved it in another variable and give it the capitalize

first_name2 = first_name.capitalize

then instead of using the variable first_name2 you use first_name here

first_name.capitalize!

like you can see it's the same fot the others..


#3

I tried

first_name = "abc"
first_name.capitalize!
print "#{first_name}"

and it worked.

The "!" actually modifies the variable itself, instead of just returning a value. The first_name2 doesn't really matter, it's actually getting a return value, which doesn't modify the first_name itself.
Overall it should work. I believe you're doing the right thing, it was just a transient issue with the IDE.


#4

You can chain all your methods in this case like

var = gets.chomp.method!

You don't have to declare so many vars.


#5

I also tried this way:


It still doesn't want to capitalize the inputs.


#6

then you lake the final print right


#7

Try puts instead of print. It's the only difference between our code pieces, and mine works fine.


#8

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