!capitalize returns blanks in string


#1



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


Is this code correct? When I run it the variables return blanks.

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

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

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

print "What state or province are you from?"
state = gets.chomp.upcase!

print "Your name is #{first_name} #{last_name} and you are from #{city}, #{state}. "


#2

Since your program takes input, it seems relevant to your question what input you are providing.


#3

This code seems to be reacting relatively weird... I just tried copying/pasting your code. When I entered something capitalized for first name, last name, city, and state - it printed out blanks for the first three, and then printed out the state. When I entered all of the above in lower case, it worked perfectly fine. The way that seems to always (pretty sure) word would be to use 1 line after each of them to perform the capitalization/upcase...

first_name = gets.chomp
first_name.capitalize!
...


#4

Well done, you've found some input that reproduces the issue.

Next up is finding out what values the "blank" variables refer to, and where they are coming from.

Documentation for the String method capitalize!
http://ruby-doc.org/core-2.2.0/String.html#method-i-capitalize-21