Redacted 5/6


#1

The code is supposed to replace a chosen word in the sentence with "REDACTED"
It works, but codeacademy doesn't seem to want to accept it. Can anybody see the problem?

puts "Write a sentence for us 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


#2

What error are you getting?


#3

It was telling me to make sure it prints every word of the input, and print REDACTED otherwise, which it did. I refreshed a few times and it let me into the next lesson, so I've got it now.

Thank you for the response, though!


#4

Add a space behind REDACTED.

so print "REDACTED "

The course is looking for a specific output.


#6

Hey Wolflash,

in the example given above 'word' is defined. It is the iterator passed in the do loop:

words.each do |word|

This line defines word as a usable variable which will change on each iteration of the array. Moreover, having 2 ends is 100% correct because we have 2 blocks here. 1 do loop, and 1 if case.

The only issue with this code in regards to meeting the course goal, is that it does not add a space after REDACTED so you will see in the output that the next non-redacted-word is attached to REDACTED.

Best,
J