Redacted redacted redacted


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-mzrZ6/0/5?curriculum_id=5059f8619189a5000201fbcb#


So technically this code works as it lets me move onto the next lesson, but when I run it it redacts all the words in my string, not exclusively the one I told it to. What am I doing wrong?


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

words = text.split(" ")

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


#2

Write this with a comparison operator, instead:

  if word == redact

Or you could write the conditional like so,

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