18/19 stuck


#1

Hi, not sure what's wrong here, can't seem to square the numbers in the array.

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

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

its keeps giving me an error of: Oops, try again. It looks like your block doesn't print the square of each number in my_array to the console using 'puts'.


#2

I have figured it out , but still interested to hear an explanation if anyone wants to provide one so other people will figure it out later :smile:


#3

doing the instruction:

n * n

by itself will not do anything else than evaluating the result.

If you want to store this result in n, then you need something like:

n = n * n

Or even:

n *= n