18. Blocks

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/ruby-beginner-en-ET4bU/4/3?curriculum_id=5059f8619189a5000201fbcb#

<In what way does your code behave incorrectly? Include ALL error messages.>
Hi,

So i’m kind of lost with this exercise. I found the correct answer by using the hints, but i just don’t understand why we must use “Sum = 2”.

My code looks like this :

```

my_array = [1, 2, 3, 4, 5]
sum = 2

my_array.each do |n|
sum = n*n
puts sum
end

And i found out it was correct but... why sum = 2 on line 2 ? I get why sum = n*n since i needed to multiple each value with itself but i'm really lost about the line 2. Does someone have an explanation ?

Thanks a lot !
<do not remove the three backticks above>

Try deleting it and see if it makes a difference before you ask about why it’s required

2 Likes

I did and it does when i did it the first time (i got an error message). Now, it doesn’t. It does’nt make any sense to me but hey… i guess it was a bug then.

Thanks anyway !

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