What the hell is wrong with my code!


#1


https://www.codecademy.com/en/courses/ruby-beginner-en-mzrZ6/0/4?curriculum_id=5059f8619189a5000201fbcb

Oops, try again. It looks like you didn't print each word from the user's text to the console.


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 word + " "
  else
    print "REDACTED "
  end
end


#2

You're getting ahead of yourself. You will do this next lesson. The code that should be from the next lesson is below. The only issue I see is that you reversed your if statement when the instructions told you to do it a different way.

puts "What text should we search?"
text = gets.chomp

puts "What word should we redact?"
redact = gets.chomp

words = text.split(" ")

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

#3

Oops, try again. It looks like you didn't print each word from the user's text to the console.


#4

Are you possibly not typing anything at the prompts?


#5

what am i doing wrong?


#6

Like I said you're only supposed to do what the directions tell you. You're trying to do more that will get done in the next lesson. Remove the if statement in your do and just print each word in words.


#7

Thanks for the help, dude i never would have got that, the hint made me think that you needed an if statement


#8

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