10 / 12

now i got an error in the interpreter saying

(ruby):2: syntax error, unexpected tIDENTIFIER, expecting keyword_then or ';' or '\n'
my_array.each { |x| if x % 2 == 0 puts x}
                                      ^

my code was

my_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

my_array.each { |x| if x % 2 == 0 puts x}

but it still let me pass that lesson. Was wondering if someone can confirm if this looks correct. if not please say something.

you forget how to use if method

No he didn’t exactly, but if you look at the code:

[quote=“killerdevildog11, post:1, topic:10948”]
my_array.each { |x| if x % 2 == 0 puts x}
[/quote]___
There are two things missing: then and end
-All together, it could look like this, it worked for me without error

my_array.each { |x| if x % 2 == 0 then puts x end}
1 Like

my code:

my_array.each { |x| puts x if x%2==0}

is this ok?

2 Likes

After entering your code, an error message appears saying:
(ruby):2: syntax error, unexpected $end, expecting '}'


But when I enter my code in the reply, the list is written out in the top right:
-It’s kind of blurry when you zoom in, sorry

I think wolflash is correct. Another way would be:

my_array.each do
    |x| puts x if x % 2 == 0
end
1 Like

I had the same error till I added spaces between the x and % and 2

my_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

my_array.each { |x| puts x if x % 2 == 0}

1 Like

The way I did it:

my_array.each {|a| puts a if a.even?}

my_array.each { |v| puts v if v % 2 == 0}

This works