The function takes a word as input and returns the capital of the country if the input is a country name. If the input is a city name with the word "City" in it, such as "New York City" or "Mexico City", the last word ("City") is replaced with the country's name. In other cases, the function returns 'undefined'.

