Help with Control Flow Know How


#1



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


#2

Consider removing whitespace between keyword and (' ').

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

Someone last week suggested reversing the order of the conditional:

if word != redact
...

#3

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