Exercise 4 of 6 in Redacted!

On exercise 4 of 6 in Redacted at : https://www.codecademy.com/en/courses/ruby-beginner-en-mzrZ6/0/4?curriculum_id=5059f8619189a5000201fbcb
My Code is:

puts "Text to search through: "
text = gets.chomp
puts "Word to redact: "
redact = gets.chomp

words = text.split(" ")
words.each do |word|
if word = redact
print "REDACTED "
else
print word + " "
end
end

What am I coding wrong here to get this error message:
Oops, try again. It looks like you didn’t print each word from the user’s text to the console.

1 Like

here this worked for me:

puts "Text to search through: "
text = gets.chomp
puts "Word to redact: "
redact = gets.chomp

words = text.split(" ")

words.each do |word|
print word
end
you should not have your if/else statement just yet

hope this helps

This is exactly what I have… but I’m still getting the “Oops, try again. It looks like you didn’t print each word from the user’s text to the console” message.

U got some problem with == and =. = is not equals operation. Check 8 line in your code.
And actually perfect to use words in foreach cycle (7 line).
like words.each do |words|

If I’m not mistaken, I believe your issue is as I state below. I don’t think it has anything to do with |word|
In your line of code (line 8), you’re setting word = to redact, you’re not actually checking to see if the two words are equivalent. The correct code should be:

if word == redact
   ...

Let me know if this resolves your issue, if not I’ll manually try and figure it out.

you’re right that actually worked i believe it probably was too early for the if statement.

Thank you