Redacted 5/6 not printing all words


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-ruby/lessons/redacted/exercises/control-flow-know-how?action=lesson_resume&link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>

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

I’ve done this, the output looks correct to me, however I cannot pass this.

output:

What is the text that you would like to search
abc def ghi jkl
What is the string you would like redacted
abc
REDACTED def ghi jkl

CODE:

puts "What is the text that you would like to search"
text = gets.chomp
puts "What is the string you would like redacted"
redacted = gets.chomp

words = text.split(" ")

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



#2

It looks here to be a problem on Code Academy’s end with variable naming. For anyone who finds this in the future, change

redacted = gets.chomp

to

redact = gets.chomp

and all of the following uses of that variable. You will then be able to pass.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.