Trouble in "Formatting with String Method"


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-ruby/lessons/putting-the-form-in-formatter/exercises/formatting-with-string-methods?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
When I type in my code, I don’t get any error messages, and it won’t even force close or give me any indication that I did something wrong. All it shows me is the loading circle, or “Run”. However, if I press run, it won’t change my situation. Any tips, or how to change my code to make it work?

```

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

print "What’s your last name?"
last_name = gets.chomp
last_name = "Street"
puts "Your last name is #{last_name}!"
last_name.capitalize!

print "What city do you live in?"
city = gets.chomp
city = "Harwich"
puts "You live in #{city}!"
city.capitalize!

print "What state do you live in?"
state = gets.chomp
#You can abbreviate your state or province
state = "MA"
puts "You live in #{state}!"
state.upcase!

<do not remove the three backticks above>

Hi, little help with an exercise
#2

EDIT - SOLVED
Got code after waiting for the program to let me continue. No help needed. Thanks.


#3

When you Run, the program is waiting for you to type in the first name, then the last, etc. We are prompted four times and each time must enter some text.

What is your first name? Danny
What is your last name? Street
What city do you live in? Harwich
What state do you live in? MA

The user cannot see this comment. It should be included in the prompt.

Now as to the outputting, your code is outputting individual entries, before they are capitalized. Best to get all the inputs, first, then output everything at once, after string processing is complete.

puts "Your name is #{first_name.capitalize!} #{last_name.capitalize!} and you live in #{city.capiltalize!}, #{state.upcase!}."

or if you do the full processing with each input,

puts "Your name is #{first_name} #{last_name} and you live in #{city}, #{state}."

#4

Thanks for clearing things up.


#5

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