Lesson 4 whats wrong with code


Okay what is wrong with this code
lesson 4 of redacted
i get oops, try again. it looks like you didn't print each word from the user's text to the console.

puts "text"
text = gets.chomp
puts  "text"
redact = gets.chomp

words = text.split(" ")

words each do |word|
    print words


There are two problems in your code.

each is a method and should be preceded with the dot.

Inside the each block you want to print only the current word (word), not the whole list of words (words).

words.each do |word|
    print word


so i changed the code to have the dot and changed words to word and still not print out its like it not getting anything from puts here is a


i really can't figure this out... I have been stuck on it for three days i want to move on but i am doing at pre course work. any ideas!?

lesson 4 REDACTED


Let's talk a bit about your previous screenshot. It clearly shows that you have executed the code and then modified the code. It does not make any sense to do that, especially if you want someone to help you.

its like it not getting anything from puts

Well, it should not take anything from puts. We use puts to print out something to the console, right? If you want to get the input from the user you have to use gets.chomp.

Your code is correct and it outputs the correct output for the input you have given. In the console (black box, right upper corner) provide some input, do not skip with the enter.

This is how the console window should look like:

Text to search through:
My name is Levi Smith
text to redact:
["My", "name", "is", "Levi", "Smith"]


sorry about the lack of clarity the edits that have been done are in order to get the code to run or to hide other info.

so here is what i am getting now.

thank you for the response


Ok, follow these steps, carefully:

  1. Change line 9 to print word
  2. Click Save & Submit Code
  3. Now type My name is Levi Smith and press Enter
  4. Now type Levi and press Enter
  5. Mission accomplished

What happens in the 3rd step? String value "My name is Levi Smith" is assigned to the text variable.


thank you i didn't realize it needed my input after running the code.


You're very welcome :slight_smile:


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