I can't get past Loops and Iterators


#1


HI guys.

Having trouble with:

https://www.codecademy.com/courses/ruby-beginner-en-XYcN1/2/5?curriculum_id=5059f8619189a5000201fbcb

If I enter:

odds = [1,3,5,7,9]

odds.each do |x|
x *= 2
print= "#{x}"
end

I get the error message:
Oops, try again. It looks like your iterator didn't print out double the value of each item of the odds array. Make sure to multiply each item by 2.

And it prints:

[1, 3, 5, 7, 9]

to the console.

`


#2

Remove this line,

and change this line to include the print statement like,

print x*2


#3

Hi. Thanks for replying!

This time I printed:

odds = [1,3,5,7,9]

odds.each do |x|
x *= 2
print x*2
end

?

and I got:

412202836[1, 3, 5, 7, 9]

in the console instead. But I still got the following error message:

Oops, try again. It looks like your iterator didn't print out double the value of each item of the odds array. Make sure to multiply each item by 2.

I don't know how I got 412202836.


#4

Oh wait, I figured it out; I had to just print:

odds = [1,3,5,7,9]

odds.each do |x|
x *= 2
print x
end

instead. Thanks again!


#5

You're welcome :slight_smile:


#6

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