Control Flow Know-How


Why do I get this correctly, when if should technically replace Alfa with redacted?

Replace this line with your code.


There must be enough required elements in the submission to satisfy the lesson checker, but this code should definitely not have passed. No matter. You at least recognize that there is a problem and stuck around long enough to find out more. That's a crucial aspect of self-learning.

Foregoing any inputs that may be required, we can use your constants since we know that the lesson will pass without user input. You start with an array, which is fine. User input would be split to form one so that step is taken. Perhaps store your chosen word in a variable so it is not a part of the code.

redact = "alfa"

We cannot compare an array to a string, so,

if words == 'alfa'

will never be true.

There seems to be some missing code, here. The each statement.

words.each do |word|


Now inside the loop body we would add the if statement.

    if word == redact
        print "REDACTED "    # remember to include the space character
        print word + " "

Note the difference between the array name and the block parameter:

words => array
word  => block parameter


Thanks a lot, will go back to that block and apply it!


Actually, I still don't pass. I am a bit confused about the structure of where one should place the isolated variable and word; does that matter? (in my case redact = "alfa")
When you say inside the loop body, I assume it is the way I have structured it?

I get the following error message: (ruby):8: syntax error, unexpected $end, expecting keyword_end


You have left off the end keyword for each.

... each do 
    if ...


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