Codecademy allowing me to move to next step with broken code?

Hi.

I’m trying to get through the ruby track but I have run into an exercise that is giving me headaches

https://www.codecademy.com/courses/learn-ruby/lessons/redacted/exercises/control-flow-know-how

This is my problem: my code is supposed to redact whatever input I choose for redact on the fourth line.

Except it doesn’t.

What am I missing?

Thank you in advance for your help.

Oh and while I’m at it, I’m not sure why i need two ‘end’ either.

Here is my code so you can copy past it, and a screenshot to be more legible:

puts "What text do you want redacted? "
text= gets.chomp

puts "What word should be redacted? "
redact = gets.chomp

words = text.split(" ")
words.each do |redaction|
if words == redact
print "REDACTED "
else print redaction + " "
end
end

image

Hey there, welcome to the forums.

Couple things you’ll want to look at:

  • Check line 2, you’re missing a space
  • On line 8, you need to consider what we’re doing:

For each word that appears in words, if a word matches the word to be redacted (redact), print “REDACTED”. Else, print the word + " ".

First end closes the if / else statement.
Second en closes words.each do

HI.
That got me unstuck.
I still need to get the hang of the |actions| becaue I keep messing them up.

Thank you. Have a nice day.