irken Posted January 15, 2007 Share Posted January 15, 2007 Hi.I'm trying to split the numbers being output into a new line every 7th number. So far no success. I'm using, plain and simple:[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled 1</title><script language="javascript" type="text/javascript"> var i = 1; while (i <= 49) { if (i % 7 == 0) { document.writeln('<br />'); } document.writeln(i); i++; } </script></head><body></body></html>[/code]Now, this outputs:[quote]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 [/quote]I'm trying to do ([b]added 0's before numbers for better reading/alignment, this does not have to be in the code[/b]):[quote]01 02 03 04 05 06 0708 09 10 11 12 13 1415 16 17 18 19 20 2122 23 24 25 26 27 2829 30 31 32 33 34 3536 37 38 39 40 41 4243 44 45 46 47 48 49 [/quote]Ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted January 15, 2007 Share Posted January 15, 2007 i%8 Quote Link to comment Share on other sites More sharing options...
irken Posted January 15, 2007 Author Share Posted January 15, 2007 [quote author=emehrkay link=topic=122483.msg505217#msg505217 date=1168877797]i%8[/quote]Well I tried that. It outputs:[quote]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 [/quote] Quote Link to comment Share on other sites More sharing options...
irken Posted January 15, 2007 Author Share Posted January 15, 2007 I guess I could do [code] var i = 1; while (i <= 49) { if (i == 8 || i == 15 || i == 22 || i == 29 || i == 36 || i == 43) { document.writeln('<br />'); } document.writeln(i); i++; }[/code]But that feels kinda stupid when you can do it using the first version, a much shorter and cleaner way. I just can't figure out why it's not doing as I like. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted January 15, 2007 Share Posted January 15, 2007 my bad try this(i - 1) % 7 Quote Link to comment Share on other sites More sharing options...
irken Posted January 15, 2007 Author Share Posted January 15, 2007 [quote author=emehrkay link=topic=122483.msg505290#msg505290 date=1168883850]my bad try this(i - 1) % 7[/quote]Excellent, that solved it.Thank you very much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.