Cool, no? Now it’s your turn to take the .each method for a test drive.

numbers = [1, 2, 3, 4, 5] # one way to loop numbers.each { |item| puts item } # another way to loop numbers.each do |item| puts item end
  1. In the example above, we create an array called numbers.
  2. Then we show two different ways to print each item in numbers to the console.



Use the .each method on the odds array to print out double the value of each item of the array. In other words, multiply each item by 2.Make sure to use print rather than puts, so your output appears on one line.

Check the Hint if you get stuck!

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?