Redacted 4 : didn't print each word from the user's text to the console


#1

I don't know what is wrong with my code.

puts "Give me your text"
text = gets.chomp
words = text.split(" ")
print words
words.each do |word|
    print word
end

puts "Give me the word to search for in your text"
redact = gets.chomp

#2

Try :
words = ["Give","me","your","text"]
print words


#3

Hi! :slight_smile:

So, in this exercise (4) we were supposed to add the .each loop in the previous code.

It should look like this:

puts "Text: "
text = gets.chomp
puts "Hide: "
redact = gets.chomp
words = text.split(" ")
words.each do |word|
print word
end

If you put in a different order, the program won't run as it should. Or at all.


#4

So I'm lost. Which of the two examples shown here works?


#5

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