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


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

'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 "
     print word + " "


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


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


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


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

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

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


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


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


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!


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