Redacted lesson 4 error message


#1

this is my code for the exercise,
puts "text"
text = gets.chomp
puts "redact"
redact = gets.chomp
words = text.split("")
words = ("")
words.each do |words|
print "words"
end
i then type in the text and the redact and the error message: "undefined method `each' for "":String comes up, though it still allows me to go to the next lesson, why does this message come up ?


#2

If your program crashed then you definitely didn't get it right. You should always check that your code has the desired effect before moving on


#3

i haven't moved on do you have any tips


#4

Look closer at the error message. It says that an empty string doesn't have a .each method.

Did you intend to use .each on a string? Can you see where in your code that happens? Do you intend for that value to be a string?


#5

What I'm saying is, you need to build yourself a clear idea of what is supposed to happen, and then compare that idea to what happened instead - this tells you which parts need to be changed.


#6

Have a look at these two lines. You just emptied your array.


#7

well the exercise wants me to write an .each loop that goes through words and just prints out each word it finds. ?


#8

Okay, so you want to be using .each on something that contains words, some kind of list. But the error message says you used it on a string right? And from that you can tell what needs to change.


#9

yes it's obvious now
puts "text"
text = gets.chomp
puts "redact"
redact = gets.chomp
words = text.split("")
words.each do |words|
print words
end