Need help with lesson 12


Here's my code:

odds = [1,3,5,7,9]
odds.each {
odds.each do |x|
x *= 2
print "The answer is #{x}\n"

However, nothing seems to be working. Can someone tell me what I'm doing wrong? Thanks.


odds = [1,3,5,7,9]
odds.each { |x| print x * 2}


Hm...I entered that code, but I still keep getting an error message. Is there anything wrong with the rest of my code?


They ask to print out double the value of each item. My code is working for sure, try to restart your browser.
You have a syntax error in each method, you mixed also { with end... In other words take away your line 2, or if you are going to keep it, try to add } to line 7. But in any case you wan't get this lesson accepted, it only as your own experiments with code


Your cleaned idea for getting double number could look like this:

odds = [1,3,5,7,9]
odds.each {|x|
print "#{x}\n"

But it gives the next to console:

[1, 3, 5, 7, 9]

As you see, the lesson is made that it just wan't pass well


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

odds.each do |placeholder|
print placeholder * 2

Essentially what you're doing is printing out X and not the variable.


The first, they do not ask to print a variable, it's told to print out double the value of each item. So, why do the calling of to print an |item| of odds array you suppose being wrong?


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