Multiplying an array by 2


#1

I am having a really tough time multiplying an array by 2.

This is currently where I'm at


#2

Hi try to remove the s to print


#3

Hello,

why doesn't work with puts? I get the following error:

odds.each { |x|
puts "#{x*2}"
}

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.


#4

HI like the insruction says..

Make sure to use print rather than puts, so your output appears on one line.


#5

Yes. I read the instruction and it works with print. However, I wanted to understand why puts should give an error. I am not concerned if it prints on one line or not.


#6

just Because with puts it will print each number on his line.... instead of what the lesson want you to do so it see it like an error


#7

That should be the only reason, as the code is not wrong..!


#8

Yes, it the only one adn yes, your code is right..


#9

I'm having the same problem too. I'm not sure if I have the coding right.

Here's what I have:

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

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

I keep getting an "undefined local variable or method" message. I've been having issues with inputting the vertical line that separates the placeholder. I'm not sure how to put that in. Could that be my issue?


#10

Never mind. I think I figured it out. I was using the wrong vertical line.