5/6 redacted issue



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 "
    print word + " "


"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.


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.


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