5/6 redacted issue


#1



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


I am not sure what is wrong in the code. Can someone please help? I have tried numerous times to reload the page but i keep getting the same error of this in the console "undefined local variable or method `word' for #" and this above the button "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!)."


puts "please write some text"
text = gets.chomp

puts "please write somthing to redact"
redact = gets.chomp

words = text.split(" ")

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


#2

"undefined local variable or method `word' for #"

means that word isn't recognized on this line if word == redact

But let's go back to analyze what you did.

You asked the user for some text, which is then split into a bunch of words.

Then, you want to single out each word among the words, except that what you did was single out all words among the words, which is why 'word' on line if word == redact was not recognized.

So what you really want to do is single out each word, in order for each word to be compared against the word to be redacted.


#3

Thank you, I actually figured it out after posting it, but thanks for explanation. I thought it was just a typo, didn't know the reasoning behind it, so very much appreciated.


#4

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