Can anyone explain why this code tells me to “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 “Write your text.”
text = gets.chomp
puts “Redact that word.”
redact = gets.chomp
words = text.split(" ")
words.each do |letter|
if letter != redact
print word + " "
else
print “REDACTED”
end
end
i think the problem in your code is here
words.each do |letter|
if letter != redact
it should be like this
words.each do |words|
if words == redact
print ("REDACT ") #and here don’t forget the Space after REDACT
else
print words + " "
and here is my full code maybe it could help
puts "Enter Your Text to Split: "
text = gets.chomp
puts "Enter The word you want to redact: "
redact = gets.chomp
words = text.split(" ")
words.each do |words|
if words == redact
print("REDACTED ")
else
print words + " "
end
end
words.each do |words|
if words == redact
print("REDACTED ")
else
print words + " "
end
end
When I changed words == redact to
words = redact I passed, but failed when set to ==
this is my end result
testing
test
redacting
test
REDACTED REDACTED REDACTED REDACTED [“t”, “e”, “s”, “t”]
I used this as mine. However, I am answer: I am human.
Then I redact human.
It lets me go to the next lesson, but does not show me human redacted?!! Does anyone know why it is letting me pass the lesson but not actually redacting human? Thanks ahead of time.
puts “What are you?”
text = gets.chomp
puts “Enter something to redact”
redact = gets.chomp
words= text.split("")
words.each do |words|
if words == redact
print "REDACTED "
else
print words + " "
end
end
which word you actually want to replace in your text
if possible show me your output
your text.split("") will simply show your word as a array of character
e.g text=roshan it will show[r,o,s,h,a,n]