Need help with lesson 12


#1

Here's my code:

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

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


#2

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


#3

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


#4

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


#5

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

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

But it gives the next to console:

2
6
10
14
18
[1, 3, 5, 7, 9]

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


#6

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

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

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


#7

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?


#8

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