Trouble with this code!


#1

Hi, I have no idea what's wrong with my code. I always get a message that says that I'm not printing each word from the user's text.

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

words = text.split(" ")

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


#2

try getting rid of this:

 + "Redacted something else"

#3

Nope. Still says the same thing.


#4

This is the message i get:

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!).


#5

if word != redact
    print word + " "
  else
    print "REDACTED "
  end

Put the "print word" in the if statement. The above code is the one I used. It could work if you did the below as well.

if word == redact
 print "REDACTED "
 else 
 print word
 end

Just take out the first "print word" before the if statement.


#6

Taking out the first "print word" worked, thanks.