5/6 pls help with my code


#1

https://www.codecademy.com/en/courses/ruby-beginner-en-mzrZ6/0/5

this 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

I keep getting the following message:

Oops, try again. Make sure to print each word from the user's text to the console unless that word is the word to be redacted; if it is, print REDACTED (all caps!).

what am i doing wrong? pls help


#2

It could be the SCT expects !== redact?


#3

Just tried it, i got a syntax error


#4

My bad. Typo. !== should be !=. Pardon me.


#5

No worries! I still get: Oops, try again. Make sure to print each word from the user's text to the console unless that word is the word to be redacted; if it is, print REDACTED (all caps!).


#6

Hate to ask the obvious, did you switch the actions in the if statement?


#7

Just tried that, i still get Oops, try again...


#8

So this isn't working?

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

#9

nope...


#10

Be sure to input both a text phrase at the one prompt, and a word to redact at the other.


#13

i don't know what i'm doing wrong


#14

to re-iterate. You are not entering any strings.


#15

Oh wow, i don't know why that took me this long to process. It worked, thanks for your help!


#16

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