4/6 Redacted


#1

Hi, I have been looking everywhere to find the solution to this but have no luck can someone help me please here is my code:

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

words = text.split(" ")

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

Thanks in Advance :grinning:


#2

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

words = text.split(" ")

words.each do |word|
    print word
end

#3

i tried this code, but it still did not work. please help


#4

Rubyblaster ignored the "if" part altogether...

I assume you're getting a "conversion from array to string" error given your "if word == redact" instead of "if word = redact"

This is what I have. It'll pass the test, but doesn't operate correctly:

puts "Recipe for disaster"
recipe = gets.chomp

puts "What would you like hidden?"
redact = gets.chomp

pieces = recipe.split(" ")

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

Anyone know why the coding is returning as if all words are redacted?


#5

puts "What word(s) shall I replace?"
text= gets.chomp
puts "What word(s) shall i replace it with?"
redact = gets.chomp
words = text.split(" ")
words.each do |word|
print word
end


#6

Hello digitalslayer25257

In reference to your question above: "Anyone know why the coding is returning as if all words are redacted?"

It is because you have used "=" instead of "===".

"=" can be used to create a variable, for example "my_age = 28"). Whereas "===" means 'equal to'.

Here is an example of code that should work:

puts "Enter text from Mr. Turing's secret notes: "
text = gets.chomp

puts "Word to be redacted: "
redact = gets.chomp

words = text.split(" ")

words.each do |spy|
if spy === redact #Your question resolved here
print "REDACTED "
else
print spy + " "
end
end


#7

Why do you state "end" twice at the bottom?


#8

Cause have DO and IF to END.


#9

Shouldn't it be == since this is Ruby instead of other languages?