Need some help with this exercise


#1

whatdid I do wrong?? I cant figure this out and need some help

puts "input 1"
text = gets.chomp

puts "input 2?"
redact = gets.chomp

if text == redact
print "REDACTED"
else
print text + redact
end


#2

What was the lesson you are on? It seems as if you aren't following the lesson plan as it's provided. I'm not sure exactly how you came to the conclusion you did for you code. (I'm not trying to be mean, I am genuinely curious)


#3

I don't even know, im still learning lol. I'm on ruby lesson REDACTED! and its number 5


#4

I don't even know, im still learning lol. I'm on ruby lesson REDACTED! and its number 5


#5

I don't even know, im still learning lol. I'm on ruby lesson REDACTED! and its number 5


#6

What you will want to do is after the line

redact = gets.chomp

pretty much delete that code. You're going down the wrong train of thought with this one.

Try this.

words = text.split(" ")   #You'll use this to take apart your text variable

words.each do |word|      #For every "words" in the "text" variable set on the previous line it will separate the variables text
    if word != redact     #If the word isn't being redacted leave it alone
        print word + " "
    else
        print "REDACTED " #Otherwise replace the word with REDACTED
    end
end

#7

Thanks for your help!


#8

puts "text"
text = gets.chomp
puts "redact"
redact = gets.chomp
words = text.split(" ")
words.each do |word|
if word = redact
print "REDACTED"
else
print word + " "
end
end

What is the difference between these 2 the top one fails but the bottom program works.

puts "text"
text = gets.chomp
puts "redact"
redact = gets.chomp
words = text.split(" ")
words.each do |word|
if word != redact
print word + " "
else
print "REDACTED"
end
end


#9

The program above won't work because of a very simple reason, you wrote if word = redact

while what should be there is : if word == redact