Wont print out REDACTED


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<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?link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>
There is no error code just prints out the words i asked to be be printed but x2
ie ( what ends up printing: )
Enter some text:
hi im sai
Enter word to redact:
sai
hihi imim saisai

```

My code -->

puts "Enter some text: "
text = gets.chomp

puts "Enter word to redact: "
redact = gets.chomp

words = text.split(" ")

words.each { |word| print word 
if word == redact 
  print "REDACTED "
else 
  print word + " "
end}
<do not remove the three backticks above>

#2

this line:


words.each { |word| print word 

why did you put print word? this will always causes the word to be printed, we only want the word if it isn’t redacted (else clause)

once i fixed that, its redacted fine:

Enter some text: 
hello world
Enter word to redact: 
world
hello REDACTED 

#3

very strange for me it still wont redact the word after i deleted the ‘print word’ as you said to do


#4

this is your code i am running:

and its working fine, ensure no additional spaces are added to enter word to redact


#5

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