There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Hi,
the redacted program is not allowing me to enter the word that has to be redacted. Instead, the original text is once again printed. Why would that be?
Yes, I’ve noticed the same thing when using .chomp. Not always, or in every lesson, but frequently enough to be a bit frustrating. I’ve noticed that you have to be quick to type in a response in the console. That seems to help most of the time. Good luck!
Hello, @array3789857647. Welcome to the forum.
Actually the way the variables are used in the lesson it works quite well. Here’s a more simple example of how the .each method works:
my_array = ["My", "dog", "has", "fleas."]
my_array.each do |potato_soup| #the variable between the pipes | | is a placeholder
print potato_soup + " " #the placeholder holds each value of the array one at a time
end
Output:
My dog has fleas.
The .each method will allow us to perform some action(s) involving each element of an array. In my cheesy example, I take an array of words, and combine them into a sentence by printing them one at a time. The variable between the | |'s will hold each element of the array one at a time, so we can refer to it in our code. We can give the placeholder variable any legal variable name. In the lesson, using a variable named word to hold the values of the words array makes perfect sense. My example makes little sense, but illustrates the concept that the name of the placeholder can vary to our individual taste. Whatever we put between the | |'s is the name we use in our code.
So the example at the very start of this chapter, I click run. It asks me to enter a phrase, I do and then it times out with “execution expired” why is it not displaying the second puts so that I can enter the word to be redacted? I haven’t touched the code yet this is the starting example…
hi, on the first part of redact topic, the code written like this.
puts "Text to search through: "
text = gets.chomp
puts "Word to redact: "
redact = gets.chomp
words = text.split(" ")
words.each do |word|
if word != redact
print word + " "
else
print "REDACTED "
end
end
Could someone help me to explain why we code double ‘end’ at the end of the code? thank you for your help. I tried it with one ‘end’ the code didn’t work. I’m cant find the answer why the ‘end’ is two.
I have found that, to enter text at a prompt in the console, you need to touch the little “keyboard” thing at the bottom of the editor window, after you touch the spot where the text prompt is (I am using an iPad). Otherwise, when you start to type your text, it defaults to typing in the editor and not the console.
To speed things up, I pre-typed the string I wanted to enter in a notes app and then copied it to paste in at the text prompt: “Once upon a midnight dreary, while I pondered, weak and weary”
Then at Text to Redact prompt, I typed ‘weak’.
Here is the result:
———— Text to search through:
Once upon a midnight dreary, while I pondered, weak and weary Word to redact:
weak
Once upon a midnight dreary, while I pondered, REDACTED and weary
————