Problems with 4/6.redacted


#1

hi guys,i m stuck at redacted part 4
here is the link

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

and this is my code below:

puts "please type your keyword"
text=user_input.gets.chomp
words=text.split(" ")
words.each do|word|
print word
puts "redact words"
redact=user_input.gets.chomp
end

actually i don't quite understand the part of this course. and could anyone tell me why is my code wrong and how could i correct it? i'd be very grateful. Thank you.


#2

text = gets.chomp

redact = gets.chomp

Both inputs can be done at the beginning of the code.


#3

it doesn't work :confounded:
and i don't understand your lesson too.
my puts is "type your keyword"
and you asked me to correct the text=user_input.gets.chomp by text=gets.chomp but there is no relationship between "type the keyword" and the text=gets.chomp. i don't understand how did the system know what i wanna it do.


#4

puts "Please enter some text"
text = gets.chomp
puts "Enter a word to redact"
redact = gets.chomp

gets is Ruby's way of acquiring inputs. The return value is a string ending in /n (a form of white space, newline). chomp is a method that removes trailing whitespace from a string.


#5

thank you for your explanation.
but i correct my code by this

puts "please type your keyword"
text=gets.chomp
words=text.split(" ")
words.each do|word|
print word
puts "redact words"
redact=gets.chomp
end

and now why is it still wrong? it says "It looks like you didn't print each word from the user's text to the console."


#6

sir i change my code by this

puts "please type your keyword"
text=gets.chomp
puts "redact words"
redact=gets.chomp
words=text.split(" ")
words.each do|word|
print word
end

and then i passed this lesson.
but why? i don't know the difference between

puts "please type your keyword"
text=gets.chomp
words=text.split(" ")
words.each do|word|
print word
puts "redact words"
redact=gets.chomp

end

just because of the order?


#7

This should not be inside the loop.

puts "Please enter some text"
text = gets.chomp
puts "Enter a word to redact"
redact = gets.chomp

words = text.split(" ")
words.each do |word|
  print word
end

#9

Yeah works for me! Thanks Sr =)