5. control flow know how


#1



hi, i found it difficult to bypass the error pops up in my answer in 5. of Redacted !, so i sources from uncle google and found this answer but i dun quite underastand it.


puts "Text to search through?"
text= gets.chomp
puts "word to redact"
redact= gets.chomp
words= text.split("")
words.each do |word|
if words ==redact
print "REDACTED"
else
print ("#{word} ")

i am confuse here, why a # here made the system run and show no error?

end
end
and its different from the on put up by the academy in the 1 of redacted


puts "Text to search through: "
text = gets.chomp
puts "Word to redact: "
redact = gets.chomp

words = text.split(" ")

words.each do |word|

why this is |word| but no |words| here?

if word != redact

why this is word but no words here?

print word + " "

why this is word but no words here?

else
print "REDACTED "
end
end


and this is my answer with the error message 
'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!).

Replace this line with your code. 
puts "Where are the information locate?"
text= gets.chomp
puts "where are you?"
redact= gets.chomp
words= text.split(",")
words.each do |words|
    if words == redact
        print "REDACTED"
    else
    print words
end
end


#3

@seanix,

You are asked to give a text
text="this is a text"

Then you are asked to give a =word= which is assigned to the variable redact
for instance
redact = "text"

With
words= text.split(",")
you transform the text in a =list= and assign this =list= to the variable words
words = ["this","is","a","text"]

With
words.each do | word | .... end
you will iterate over the =list= words
and with each iteration an Element-Value is assigned to the variable word

With your print don't forget to add an extra space character....!!!