Help with Control Flow Know How


Lesson 5 of Redacted!

The code replaces the word that is set to be redacted as as the term "REDACTED". However the error message reads that "Oops, try again. 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 think my code does just this but I'm very confused. I looked at similar issues on the forum but am still having trouble solving it.

puts "Please enter a phrase."
text = gets.chomp
puts "Redact which word?"
puts redact = gets.chomp

words = text.split (" ")
words.each do |word|
    if word == redact
        print "REDACTED"
        print word + ""


Consider removing whitespace between keyword and (' ').

The whitespace is missing. "REDACTED ", ... + " ".

Someone last week suggested reversing the order of the conditional:

if word != redact


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