0

我正在学习 Codecademy 课程以快速了解 Ruby 的基础知识,但我在他们的编辑中遇到了障碍!锻炼。我发布了我认为应该做的伎俩,但它拒绝打印。

练习说明如下:

让我们从简单的开始:编写一个遍历单词并打印出它找到的每个单词的 .each 循环。

如果可以的话请帮忙。谢谢!这是我的代码:

puts "What is your text, bra?"
text = gets.chomp
text.downcase!

puts "What is being hidden?"
redact= gets.chomp
redact.downcase!

words = text.split(" ")
eachredact = redact.split(" ")

#loop through the words in the string
words.each do |x|
    print "#{x}" + " "
  end
4

1 回答 1

1

我运行如下:

puts "What is your text, bra?"
text = gets.chomp
text.downcase!

puts "What is being hidden?"
redact= gets.chomp
redact.downcase!

words = text.split(" ")
eachredact = redact.split(" ")

#loop through the words in the string
words.each do |x|
    print "#{x}" + " "
end

输出:

What is your text, bra?
i anm
What is being hidden?
Good
i anm

看这里:

代码学院

于 2013-04-24T21:02:06.093 回答