Redact 5/6 - Says I passed but doesn't actually redact anything


#1

Control Flow Know How

I get no error messages. It tells me great job. But when I run the code, it doesn't redact anything.

puts "insert text"
text = gets.chomp
puts "please redact"
redact = gets.chomp

words = text.split (",")

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

#2

The text is not likely to contain any commas. Use a space character as the separator to split on.


#3

I just ran it with the comma and without the comma, they both worked for me. You are probably seeing the interpreter echoing. Something like this,

REDACTED
=> ["Joey"]

The second line is just showing you what you inputted. (VERY confidential if I say so myself!)


#4

'the difference was the comma in the text.split. Works totally fine, now.
Thank you!


#5

Quite, indeed! I see what you're saying, but even in the final line, it wasn't showing REDACTED at all. The clincher turned out to be the comma in the text.split.

Many thanks


#6

You should hit the check-mark box at the bottom of MTF's post to mark that he fixed the problem. :+1:


#7

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