Formatting with string methods


#1



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


Error: "Oops, try again. Make sure to call capitalize! on first_name, last_name, and city."


print "What's your first name?"
first_name = gets.chomp
first_name = first_name.capitalize
print "What's your last name?"
last_name = gets.chomp
last_name = last_name.capitalize
print "Where are you from?"
city = gets.chomp
city = city.capitalize
print "What state?"
state = gets.chomp.upcase
puts "Your name is #{first_name} #{last_name} and you're from #{city}, #{state}!"

I also tried to put the .capitalize right behind the gets.chomp, but that doesn't work either. The result is right, but it still shows me the error message and says it's wrong, but brings the right result..

best regards
dave


#2

Hi @daveplaya ,

Instead of this ...

first_name = first_name.capitalize

... Codecademy would like you to do this, which will have the same effect on the value of first_name. ...

first_name.capitalize!

Use a similar technique for the other variables.

The capitalize! and upcase! methods alter, directly, the strings on which they are called.


#3

print "What's your first name?"
first_name = gets.chomp
first_name = first_name.capitalize dont do this. check below code:

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 "Where are you from?"
city = gets.chomp
city.capitalize
print "What state?"
gets.chomp.upcase
puts "Your name is #{first_name} #{last_name} and you're from #{city}, #{state}!"
[/quote]

remember for example if you say:
city.capitalize! note the "!" at the end. that means you are permanently capitalizing your city user input.


#5

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