How to capitalize each word?

How to also capitalize ‘angeles’ ?

I tried .split, .map, .join, .titleize

What are you doing at the moment? Are you using capitalize?

To apply to all words in a string, you have to split the string into words, apply your change, and then rejoin the array:

2.7.1 :001 > x = "los angeles"
2.7.1 :002 > y = x.split(' ').collect(&:capitalize).join(' ')
2.7.1 :003 > y
 => "Los Angeles"
1 Like
# Prompt the user for input. #

print “What’s your first name?\n”
first_name = gets.chomp

print “What’s you last name?\n”
last_name = gets.chomp

print “What’s your city?\n”
city = gets.chomp

print “What’s your state’s abbreviation?\n”
state = gets.chomp

Formatting the output with string methods.

city = city.split(’ ‘).collect(&:capitalize).join(’ ')

Print the Output.

puts “Your first name is #{first_name}”
puts “Your last name is #{last_name}”
puts “Your city is #{city}”
puts “Your state is #{state}”

End of script.

Is ‘city’ right now ?

That worked. thanks for the help.