 # 9.9 Next Method

Why am I not able to print just odd numbers. I don’t understand what I am supposed to do or how to get it there. I get that the number is being divided and then the remainder if equal to 0 is skipped. So do I just have to find a number that skips all even numbers?

Javascript has the so-called modulo / remainder-operator if used it will return the rest-value.

9%3 You read it as nine modulo three is zero, as 9 divided by 3 has NO rest-value.
22%6 You read 22 modulo six is 4, as 22 divided by 6 will leave you with rest-value 4
16%8 You read it as sixteen modulo eight is zero, as sixteen divided by 8 has NO rest-value.
Now for the exercise 2/33:

``````var multiplesOfEight = [8,16,24,32,40,58];
|  |  |  |  |  |
multiplesOfEight  |  |  |  |  |
multiplesOfEight  |  |  |  |
multiplesOfEight  |  |  |
multiplesOfEight  |  |
multiplesOfEight  |
multiplesOfEight
``````

multiplesOfEight --> 8
multiplesOfEight --> 24
multiplesOfEight --> 58

multiplesOfEight%8 --> 8%8 --> 0
multiplesOfEight%8 --> 24%8 --> 0
multiplesOfEight%8 --> 58%8 --> 2

== the Book ==
javascript remainder operator site:developer.mozilla.org

== discussions / opinions ==
javascript remainder operator site:stackoverflow.com
= http://stackoverflow.com/questions/4467539/javascript-modulo-not-behaving
javascript array site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

If you want to check if a number is even,
you can use

``number%2 === 0``

@leonhard_wettengmx_n

for i in 1…5
next if i % 2 == 0
print i
end

Here is the example. but it wants it from 1 to 18 skipping odd numbers. It wants me to skip to the next iteration if the number is odd. And I am in ruby. what you posted earlier I am not that far in. Thank you though for the information. The typed part cleared up what the computer was reading.

Thats how my code looks like as well. I run into an error as well.
Error: Oops, try again. It looks like your loop doesn’t print out the numbers 18 to 0.

for i in 1…5
next if i % 2 == 0

print i

end

What is the solution ?

@ameyparab

Excellent question. All I changed was:

for i in 1…18
next if i % 3 == 0
print i
end

I changed it to 3 thinking that if 2 made if print odd numbers then maybe 3 will make it print even numbers.

loool u guys are funny all u had to do was change == to != meaning not equal to

i = 20
loop do
i -= 1
next if i % 2 != 0
print “#{i}”
break if i <= 0
end

5 Likes

• leave one blank-line above of your code
• select your code in the Post
• then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use