REDACTION: Word to be redacted AND the word "REDACTED " both print. Why?


#1



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

My code will print both the word to be redacted and then the text "REDACTED " right next to each other. I'm not sure what I'm doing wrong here. Any input? Thanks

ERROR MESSAGE:
'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!).'


puts "Please enter the text you would like to redact from: "
    text = gets.chomp

puts "Please enter the word you would like to redact"
    redact = gets.chomp
    
    words = text.split(" ")

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


#2

Use a comparison operator, == instead of an assignment operator, =.


#3

I tried that, but then it repeated every single word and the word "REDACTED " next to each of them. :0


#4

Actually it just repeats every word twice, without the word REDACTED.


#5

Remove that line so it doesn't print every word.

This shouldn't matter, but try this...

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

#6

Just tried it, but it simply prints every word once and doesn't redact anything


#7

It shows the code as successful and lets me proceed, but nothing was redacted.


#8

I just realized I was putting in two words into my redaction request and the code isn't written for that. whoops!

trial and error.

thanks for your help!


#9

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