スポーツファンに情報を尋ねる簡単なプログラムを作成しました。これが私がこれまでに持っているコードです:
puts "What's your favorite pro sport?"
favorite_sport = gets.chomp
puts "Who's your favorite team in the #{favorite_sport}?"
favorite_team = gets.chomp
puts "What city are they from?"
team_city = gets.chomp
puts "Who's your favorite player in the #{favorite_team} roster?"
favorite_player = gets.chomp
puts "What position does #{favorite_player} play?"
player_position = gets.chomp
puts "How many years has #{favorite_player} played in the #{favorite_sport}"
years_experience = gets.chomp
fan_info = [favorite_sport, favorite_team, team_city, favorite_player, player_position, years_experience]
puts fan_info
プログラムに、文字列の最初の文字を大文字にして fan_info を出力させたいと考えています。どうすればいいですか?メソッドを使用する必要があることはわかっていますが、capitalize
これを実装するのに問題があります。
入力と出力の例を次に示します。
What's your favorite pro sport?
NFL
Who's your favorite team in the NFL?
Seahawks
What city are they from?
seattle
Who's your favorite player in the Seahawks roster?
wilson
What position does wilson play?
qb
How many years has wilson played in the NFL
1
NFL
Seahawks
seattle
wilson
qb
1