Redacted 6/6 Challenges - multi redacted words


Hey Guys and Girls,

I have completed the Redacted lesson and I want to go on a do the extra challenges.
I am working on a program that takes multiple separate words to redact.

Below is my code, but when I use it it prints "REDACTED" for all the words I input first.

Why is this?

puts "Give me a quote"
text = gets.chomp

puts "Take away one word"
redact = gets.chomp

puts "Do you want to take away another? Yes or No"
ans = gets.chomp
 if ans == "yes"
     puts "Ok, just one more then.."
     redact2 = gets.chomp
     print "As you wish"

words = text.split (" ")
redacts = [redact, redact2]

words.each do |word|
    if redacts.include? (word) == false
        print word + " "
        print "REDACTED "


Consider the case when the user do not want another redact word. Then your redacts array: redacts=[redact,redact2] would be meaningless!


Thanks for the reply!
Ah see your point.....

Is there a way I can use only one "redact" input and ask the user to input multiple words at the same time and get these words to be redacted from the final output....?

Many thanks


Well, maybe.
For redaction you can ask the user to enter not a word, but a group of words. Than you can split these words to be redacted by split(" "). By this way you'll have an 'array of redaction words'.
If you use this way, you have to check the user text for each element of your array.


I think I get it, I will get it a try.
Many thanks.


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