puts"I want all of your text!"
text=gets.chomp
puts"Now, what do you want to redact kid?"
redact=gets.chomp
words=text.split(" ")
words.each do |word|
print word
if word==redact:
print"REDACTED "
else
print word +" "
end
end
@bayoishola20[quote=âbayoishola20, post:4, topic:44585, full:trueâ]
This exercise is a continuation of previous exercise. So you should have it as words. See below:
words.each do |words|
if words == redact
print "REDACTED "
else
print words + " "
end
However, I noticed something. See corrected below:
text = gets.chomp
puts text
redact = gets.chomp
puts redact
words = text.split(" ")
words.each do |words|
if words == redact
print "REDACTED "
else
print words + " "
end
end
Yes that colon should not have been there - that looks more like python syntax. Also the first print word statement would not be necessary. Finally you were correct in having words and word. one represents the array of words and the other is the arbitrary variable used to mean a single word (which you could have called anything really.
my code below, and there is always the same answer â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!).â
it seems fine but i can not move on. Can you help?
puts "Text to search through: "
text = gets.chomp
puts "Word to redact: "
redact = gets.chomp
words = text.split(" ")
words.each do |words|
if words == redact
print "REDACTED "
else
print words + ââ
end
end
You donât necessarily have to change anything.
For me it worked using âwordâ instead of âwordsâ.
The thing that matters is the âendâ keyword, my solution was to put it twice, the first time for the if/else statement and the second time for the loop.