Hey there, hopefully you've figured it out by now. If you haven't, and aren't currently discouraged, I can try my best to help you out!
So for this lesson, if I'm not mistaken, you're taking in the string (sentence of however many words) as well as the word you want to remove from the sentence (redact).
Your first 5 lines of code (technically 6 lines with your spacing) are correct. After that is where you start to stray a bit. Your code currently (after line 6) prints out every word stored in the array words. This is already incorrect from what you want, considering the user isn't interested in all the words, but just the sentence with the redacted word out of it. So just a list of what you have that is incorrect:
- You print out each word that is in the sentence
- You only check if the 1 word is equivalent to redact, not even sure what that word ends up being since it's an array and I didn't run your code myself
You want to perform the
words.each loop the way you did, and then inside that loop check
if word == redact like you did. Both of your loops are correctly written, you just need to intermingle the two to get your desired outcome (the string without the redacted word).
If you still can't figure it out, I've posted my code below for you to look at, copy, paste, try, etc. Let me know if this solves your issue, and if not, I'll gladly help!
puts "Enter text:"
text = gets.chomp
puts "Pick what you want redacted from the above text:"
redact = gets.chomp
words = text.split(" ")
words.each do |word|
if word == redact
print "REDACTED "
print word + " "