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



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


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


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


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