DEV Community

jazmineubanks
jazmineubanks

Posted on

TIL 03/15/22

Today I was working in code academy trying to further my understanding of Loops and arrays. I felt like when I was going over the content about loops, it made sense in my head. However, when it came down to the practice questions, I could not figure out the answers. I believe I need to continue practicing.

One question I struggled with was:

Add an if/else statement inside your .each.

if the current word equals the word to be redacted, then print "REDACTED " with that extra space.
Otherwise (else), print word + " ".
The extra space in both cases prevents the words from running together.

The correct answer to this question is:
words.each { |word|
if word == redact
print "REDACTED "
else
print word + " "
end }

I feel like when I am reading the questions, I for some reason cannot make sense of what is being asked of me. I will try to re-read the questions and take things slower, along with my practice.

Top comments (0)