4/6 Redacted!


#1

So I have no idea what is going on. It prints all my words, and also redacted. This is my code.

puts "Please enter some text"
text = gets.chomp
puts "Enter a word to redact"
redact = gets.chomp
words = text.split(' ')

words.each do |word|
if word == redact
print "REDACTED "
else
print word + " "
end
end


#2

you have it a bit off but that isn't hard to change
try what I put below.

puts "Please enter some text: "
text = gets.chomp
puts "Enter a word to redact: "
redact = gets.chomp
words = text.split(" ")

words.each do |words|
if words != redact
print words + " "
else
print "REDACTED "
end
end


#3

Got it! Thanks! =D Much appreciated!


#4

No problem! One thing to always remember is that what you need to complete the lesson is always present within the section or prior sections. In this case I went back to the first section to compare to a working example. Have a great day!


#6

On reading this I cannot see how it would not add to confusion. A block parameter with the same name as the instance object is mighty confusing. Are words not a one word after another?

words.each do |word|
    print (word == redact ? "REDACTED" : word) + ' '
end

#7

I used exactly the same code as you but it says this:

Oops, try again. It looks like you didn't print each word from the user's text to the console.