how can i write a javascript to print evens numbers from 0 to 50 in different lines as follows
2 4 6 8 10
12 14 16 18
20 22 24 26
28 30 32 34
36 38 40 42
44 46 48 50
2 replies to this topic
#1
Posted 26 September 2011 - 05:32 AM
|
|
|
#2
Posted 26 September 2011 - 05:57 AM
There are several ways to do it, but it will depend on the HTML on your page, among many things. What do you have so far?
#3
Posted 26 September 2011 - 06:08 AM
One thing for sure, it will be easier if you have the same amount of number on each line.
Your first line have 5 number, and the other line have only 4
You will need a for that will look like this
And maybe a other variable that you increment each time you enter the for, and you test for a modulus 4 like so
Your first line have 5 number, and the other line have only 4
You will need a for that will look like this
for (i=0;i<=50;i+=2)
And maybe a other variable that you increment each time you enter the for, and you test for a modulus 4 like so
var % 4 == 0And when it's true, you print a new line.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









