.each method and loops resulting in totally unreasonable results, even if using 'Hint' code


#1

https://www.codecademy.com/courses/learn-ruby/lessons/loops-iterators/exercises/try-it-out?action=lesson_resume&link_content_target=interstitial_lesson

Some of the previous exercises with loops and this one with the .each method are outputting totally unreasonable numbers in the terminal. For example, the code below (taken from ‘hint’) outputs “26101418” in the terminal. Also does that in local irb test. What is wrong with this code?

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

# Add your code below!

odds.each do |odd| 
  print odd*2
end

#2

the result is printed on the same line, that might look confusing, maybe use puts? This will cause each result to be printed on its own line


#3

That makes more sense. I feel like an idiot, thanks :smiley:


#4

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