Redacted! 5/6


#1

I'm a bit confused
We have variable "words" buy later in the loop we use "word". Could you clarify please?
Actually the code works also if I use "words" everywhere so what is the difference?


#2

Alright, so "words" and "word" are used in two different ways.

"words" is the variable, "word" is the parameter. So let's just for now change these words to better reflect their property.

words is now "variable", word is not "parameter"

so with every parameter in variable "this" will happen. Maybe if you see it like that it'll help you understand what's going on


#3

2 more questions:
- You say: words is now "variable", word is not "parameter". Is it correct? Or do you mean "...... now "parameter"?
- Why that case if I code as follows it also works?


#4

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

This is what you have.

But this is what I mean:

puts "Type your text"
text=gets.chomp
puts "Word to redact"
redact=gets.chomp

variable=text.split(" ")

variable.each do |parameter|
 if parameter != redact
 print parameter + " "
 else print "REDACTED "
 end
end

Don't do this in your actual program, I'm just showing you what the computer sees so it's more clear what you're looking at


#5

Got you!
Would you mind if I give a small advise as I'm not native english speaker? It would be less confusing if the training program not allow to use "words" as a "parameter". Or it's not because of the soft?

One more question
As I understand parameter + " " adds spaces after each word. But how we add space after first word? For example I have a string "I love coding" and word "love" was redacted to "REDACTED ". That case space added after "REDACTED" but what about space after "I"?


#6

else print "REDACTED "
           ^

Just add a space there :smiley:


#7

LOL
The thing is there is a space without adding adding a space into "REDACTED ")))
But I've got your idea)
Thanks