# Nobody here explain 5/6

#1

``````puts "first prompt"
text = gets.chomp

puts "2nd prompt"
redact = gets.chomp

words = text.split(" ")

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

Can someone explain clearly step by step why is this the code?

Thanks``````

#2

i have noo idea but i need help on it too i entered what you did and it did not work

#3

SOLUTION:
puts "what are you looking for?"
text=gets.chomp

puts "word to be REDACTED?"
redact=gets.chomp

words=text.split(" ")
words.each do |a|
if a == redact

``````print "REDACTED "
``````

else
print a +" "
end
end

#4

thank you very much!!

#5
``````puts "first prompt" # output to SCREEN
text = gets.chomp   #  get input from KEYBOARD
# for instance "this is a test line this"
puts "2nd prompt"   # output to SCREEN
redact = gets.chomp #  get input from KEYBOARD
# for instance  "this"
words = text.split(" ") # you now create an Array of =words=
# by splitting the =text=
# using the SPACE-character as SEPARATOR
#thus "this is a test line this"
#becomes
# [this,is,a,test,line,this]   which are 6 ELEMENTS

words.each do |x|   # for each ELEMENT, =x= will get the VALUE
# first LOOP =x= will be "this"
if x != redact   # test IF the =x= VALUE is NOT-EQUAL to the =redact= VALUE "this"
# as =x= EQUALS =redact= you will jump-to the ELSE
print x + " "
else  # you come here as =x= EQUALS =redact=
print "REDACTED"
end
# now you start over with the next ELEMENT so =x= becomes "is"
end
``````

Thus
==Loop-1=
redacted = "this"
x = "this"
test x NOT-EQUAL redact is FALSE==> ELSE --> print “REDACTED”

==Loop-2=
redacted = "this"
x = "is"
test x NOT-EQUAL redact is TRUE thus --> print “is” + " "

==Loop-3=
redacted = "this"
x = "a"
test x NOT-EQUAL redact is TRUE thus --> print “a” + " "

==Loop-4=
redacted = "this"
x = "test"
test x NOT-EQUAL redact is TRUE thus --> print “test” + " "

==Loop-5=
redacted = "this"
x = "line"
test x NOT-EQUAL redact is TRUE thus --> print “line” + " "

==Loop-6=
redacted = "this"
x = "this"
test x NOT-EQUAL redact ==> ELSE --> print “REDACTED”

#6

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