Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hopefully an easy question!

    Hey! Sorry if this is a very remedial question, but I'm trying to make a table, of even and odd numbers organized in two columns (with as many rows as it takes to get through the sequence) and I'm having an issue with my code, obviously - haha. I'm still slightly new..

    here is my code

    Code:
    document.write('<table>');
    for (i=1; i < 50; i++) {
    	document.write("<tr>");
    		for (j = 0; j < 50; j++) {
    			if (j % 2==0) {
    				document.write('<td>' + j + '</td>');
    			}
    				else
    			{
    				document.write('<td>' + i + '</td>');
    			}
    			}
    }			
    				document.write("</tr>);
    				document.write("</table>");
    Any help would be greatly appreciated!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Sounds like homework!

    Code:
    <script type = "text/javascript">
    document.write('<table>');
    for (j = 0; j < 50; j=j+2) {
    document.write("<tr>");
    document.write('<td>' + j + '</td>');
    document.write('<td>' + (j+1) + '</td>');
    document.write("</tr>");		
    }			
    document.write("</table>");
    </script>

    It is your responsibility to die() if necessary….. - PHP Manual
    Last edited by Philip M; 09-06-2011 at 10:57 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •