5/6 Help Please


#1

This is my code:

puts "Text to search"
text = gets.chomp
puts "What to redact"
redact = gets.chomp
words = text.split(" ")
words.each do |word|
if word == redact
print "REDACTED"
else print word + " "
end
end

The site keeps saying "Oops, try again. Make sure to print each word from the user's text to the console unless that word is the word to be redacted; if it is, print REDACTED (all caps!)."

Please help


#2

Try inserting a space after REDACTED, if your redacted word is not the last I think the checks made by the lesson will fail.


#3

It worked when I added a space, thanks! [my code is below for anyone else]

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

words = text.split(" ")

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