Where to place upcase?

In this exercise I believe the only thing I have left to do is to “.upcase” the state variable in this code. The trouble is, I’m not exactly sure as to where place this “.upcase”.

Any help with this would be great!

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

first_name = "Kevin"
puts "Your name is #{first_name}!"
last_name = "Bacon".capitalize!
puts "Your last name is #{last_name}!"
city = "Reading".capitalize!
puts "You're from #{city}!"
state.upcase = "UK".capitalize!
puts "You're from #{state}!"

You should do some testing. Use a place like https://repl.it/languages/ruby if you don’t like seeing the oops messages here.

Have a look at what this code does:

print "What's your first name?"
first_name = gets.chomp.capitalize!
puts "Your name is #{first_name}!"

Test it with a word, first with the first letter already uppercase and again with it lowercase. What did you discover?

Let’s also have a look at these two lines:

first_name = gets.chomp.capitalize!
first_name = "Kevin"

What to you think is going on there?

What if I had answered the “What’s your first name?” prompt with fred?

Thanks for the heads up on that site albion. How do I make that first name bit more universal? Should I leave the space blank?

I can’t quite figure out what you mean by these two questions. Explain it to me slowly. :slightly_smiling:

You have to place the .upcase! after puts “your from #{state}!”
Like this print

“What’s your state name?”
state = gets.chomp.capitalize!
puts “your state is #{state}!”.upcase!

That will work nicely if you want that entire sentence in uppercase letters.

hi there! I have been stuck on this exercise for a long time.
I am copying this because the lesson is allowing me to go forward but I am still not sure I actually did it write.
In addition to getting first name, last name and city to be capitalize, I did get state to be capitalize.
The way I wrote my form though, I had to answer each question. I noticed others used print “answer” so that when you hit return, the answer would pop up. Which is correct? Below is what I typed which got the lesson to work for me.

Putting the Form in the Formatter - Lesson 6

print “What’s your first name?”
first_name= gets.chomp
first_name2= first_name.capitalize

print “What’s your last name?”
last_name= gets.chomp

print “What city are you from?”
my_city= gets.chomp
my_city2= my_city.capitalize

print “What state are you from? Use two letter code.”
my_state= gets.chomp.upcase!

puts “Your name is #{first_name} #{last_name}. You are from #{my_city}, #{my_state}!”

You don’t need those lines, you never make use of those “2” variables.

You could echo the response back like you mentioned you saw others do, if you liked that – run it a few times to see if you think that would be helpful or annoying for someone using your program.

1 Like

Thank you for the help. I didn’t realize there were multiple ways to answer the lesson. I assumed they wanted you to create a program that promoted for an answer, it were coded right you would move on to the next question. Such a learning experience. Thank you!

1 Like