How do I use .capitalize! to capitalize 2 words (such as New Brunswick)?)?


When I used city.capitalize in this exercise, the city which has 2 words only got the first word capitalized, not both as it should have been. How do I get both capitalized?



We need to create an array and then use an each block to capitalize individual terms, then join them back together.

city = 'los angeles'

y = city.split               # => ["los", "angeles"]

y.each {|x| x.capitalize! }  # => ["Los", "Angeles"]

city = y.join(' ')           # => "Los Angeles"


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