FAQ: Methods, Blocks, & Sorting - Using Code Blocks

This community-built FAQ covers the “Using Code Blocks” exercise from the lesson “Methods, Blocks, & Sorting”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise Using Code Blocks

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 (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 (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


Currently, the second .each will print out 5 five times (since it will print 5 for each item in the array, and there are five items). Modify the block so it will print each item in the array multiplied by five.

method that capitalizes a word

def capitalize(string)
puts “#{string[0].upcase}#{string[1…-1]}”

capitalize(“ryan”) # prints “Ryan”
capitalize(“jane”) # prints “Jane”

block that capitalizes each string in the array

[“ryan”, “jane”].each {|string| puts “#{string[0].upcase}#{string[1…-1]}”} # prints “Ryan”, then “Jane”

Im stuck

itś somekind of bug or an error, just refresh the webpage and you will have the rigth exercise.

[1, 2, 3, 4, 5].each { |i| puts 5 }

this one can be solved multiplying every item by 5 like this

[1, 2, 3, 4, 5].each { |i| puts i*5 }

I tried:

[1, 2, 3, 4, 5].each { |i| puts i * 5 }

[1, 2, 3, 4, 5].each { |i| }

as a result, I received:

system allowed me to proceed to next exercise.

not sure if I am correct, but the solution it gave did not make sense to me or give the answer : 5, 10, 15, 25

Put in the same solution and got the correct results. Late reply lol but yeah your answer is correct it seems.

I don’t know if you’ll get this, or even, if you are still stuck on it?
But from what I understand:

[1, 2, 3, 4, 5].each { |i|
Means each array in [ ] becomes a ‘placeholder name’ as ‘i’.

.each { |i| puts i * 5 }
Means for each ‘i’, times it by 5.
so it now becomes:
1 x 5
2x 5
3x 5
4x 5
5x 5
which in order, the answer to those calculation will be…

I hope that makes sense :slight_smile: