4. - Help me with code!


#1

puts "Text to search through: "
text = gets.chomp
words = text.split(" ")

puts "Word to redact: "
redact = gets.chomp

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

Basicaly it works well. I tested with sentence which includes lots of lol's and some nope's and make nope's redacted.


#2

Hi @gigajumper16086,

Please give the exercise link. Thank you! :slightly_smiling: Please post the error you are getting. Thanks! :slightly_smiling:


#3

https://www.codecademy.com/courses/ruby-beginner-en-mzrZ6/0/4?curriculum_id=5059f8619189a5000201fbcb

Oops, try again. It looks like you didn't print each word from the user's text to the console.


#4

The instructions state that:

Let's start simple: write an .each loop that goes through words and just prints out each word it finds.

And now see your code:

puts "Text to search through: "
text = gets.chomp
words = text.split(" ")

puts "Word to redact: "
redact = gets.chomp

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

In case word equals redact, you wouldn't be printing each word, but the exercise wants you to do so. Can you now fix your mistake? :wink: