Redacted lesson 4:6


#1

I'm not sure what I'm doing wrong:

puts "What would you like to tell me?: "
text = gets.chomp

puts "What would you like to redact?: "
redact = gets.chomp

words = text.split (" ")
words.each do |word|
 if word == redact
 print "REDACTED"
 elsif
    print word + " "
else redacts.include?(word)
    print "REDACTED"
end
end

#2

First, let's get the indentation to jive...

words = text.split (" ")
words.each do |word|
    if word == redact
         print "REDACTED"
    elsif
        print word + " "
    else redacts.include?(word)
        print "REDACTED"
    end
end

#3

If this is lesson 4, then there is way more code here than expected, so I won't even go into what could be wrong with it. Here are the instructions:

Let's start simple: write an .each loop that goes through words and just prints out each word it finds.

This should be enough to meet the expectations:

puts "Body text:"        # optional text
text = gets.chomp
puts "Redacted text:"    # also optional text
redact = gets.chomp
words = text.split(" ")
words.each do |word|
    print word
end

#4

In lesson 5 we replace the line print word with an if statement:

    if word != redact
        print word + " "
    else
        print "REDACTED "
    end

#5

Which brings us to lesson 6, and the OP code:

    if word == redact
         print "REDACTED"
    elsif
        print word + " "
    else redacts.include?(word)
        print "REDACTED"
    end

I am only going to ascertain the objective in the above, not deconstruct or correct. Could it be,

if redacts.include?(word)

which of course assumes there is a redacts list. We can still fall back on a simple if..else statement.

    if redacts.include?(word)
        print "REDACTED "
    else
        print word + " "
    end

Theoretical, mind; I still need to test this.


#6

I was copying a code from a different user and pasted too much:) Anyway, here's my code as you suggested and it still doesn't work. What did I do wrong? Thanks!

puts "Write the correct code:"
text = gets.chomp
puts "I like writing code:"
redact = gets.chomp
words = text.split(" ")
words.each do |word|
    print word
end

I'm getting this error message:
Oops, try again. It looks like you didn't print each word from the user's text to the console.


#8

puts "Text 1:"
text = gets.chomp
puts "Redact:"
redact = gets.chomp
words = text.split(" ")
words.each do |word|
print word +""
end

print word +"" => print all words
print word => print one word


#9

The following output was accepted...

theraininSpainfallsmainlyintheplains["the", "rain", "in", "Spain", "falls", "mainly", "in", "the", "plains"]

It would appear the lesson checker isn't looking for word separation.


#10

yes. because print word + "separation". so i use "" => not separation


#11

Then it comes down to the concatenation not being expected.


#12

I'm sorrry. I dont understand your opinion.


#13

The expression,

word + ""

uses concatenation (joining text) which might not be expected. Some lesson checks involve reading the actual code. If it does not match what is expected, then it does not pass.