SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    displaying patterns

    I have the labeled for below to generate a patten of :

    *
    **
    ***
    ****
    ***** ect...

    nextRow:
    for ( var row = 1; row <=10; ++ row ) {
    document.writeln( " <br />");
    for ( var column = 1; column <= 10 ; ++column ) {
    if (column > row )
    continue nextRow;
    document.write( "* " );

    How do I modify it to display this pattern, last * are aligned vertically.
    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *

  2. #2
    do righteous deeds
    Join Date
    Aug 2006
    Location
    Türkiye Turkey تركيى
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    
    for ( var row = 1; row <=10; ++ row ) {
    document.writeln( " <br />");
    for ( var column = 1; column <= 10 ; ++column ) {
    if (column >= row )  document.write( "* " );
    }
    }
    </script>
    Code:
      
    <script type="text/javascript">
    
    for ( var row = 1; row <=10; ++ row ) {
    document.writeln( " <br />");
    for ( var column = 1; column <= 10 ; ++column ) {
    if (row >= column )  document.write( "* " );
    }
    }
    </script>

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    my question did not display correctly

    my question did not display correctly the ouput I need to get is
    S= blank space

    **********
    s*********
    ss********
    sss*******
    ssss******
    sssss*****
    ssssss****
    sssssss***
    ssssssss**
    sssssssss*

  4. #4
    do righteous deeds
    Join Date
    Aug 2006
    Location
    Türkiye Turkey تركيى
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    style="text-align: right;
    Code:
     
    <body>
    
    <div id="divid" style="text-align: right; width: 100px;"></div>
    
    <script type="text/javascript">
    var el = document.getElementById('divid');
    for ( var row = 10; row >= 1; --row ) {
       for ( var column = 1; column <= row ; ++column ) {
          el.innerHTML +=  '*' ;
       }
       el.innerHTML += "<br />";
    }
    </script>
    Code:
      
    <body>
    <body>
    <div id="divid"></div>
    
    
    <script type="text/javascript">
    var el = document.getElementById('divid');
    var s = '\xa0'+'\xa0';
    for ( var row = 10; row >=1; -- row ) {
    
    s+='\xa0'+'\xa0';
    el.innerHTML += s;
    
    for ( var column = 1; column <= 10 ; ++column ) {
    
      if(row >= column) el.innerHTML +=  '*' ;
    }
    el.innerHTML += " <br />";
    }
    </script>
    Code:
     
    <body>
    
    <div id="divid"></div>
    
    <script type="text/javascript">
    var arr =[
    "**********",
    "\xa0\xa0*********",
    "\xa0\xa0\xa0\xa0********",
    "\xa0\xa0\xa0\xa0\xa0\xa0*******",
    "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0******",
    "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0*****",
    "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0****",
    "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0***",
    "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0**",
    "\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0*"
    ];
    var el = document.getElementById('divid');
    for(var i = 0; i < arr.length; i++) {
    el.innerHTML += arr[i] +"<br>";
    }
    </script>
    <body style="text-align:right;">
    Code:
    <body style="text-align:right;">
    <script type="text/javascript">
    
    for ( var row = 1; row <=10; ++ row ) {
    document.writeln( " <br />");
    for ( var column = 1; column <= 10 ; ++column ) {
    if (column >= row )  document.write( "* " );
    }
    }
    </script>
    Last edited by muazzez; May 31, 2007 at 11:16.


Bookmarks

Posting Permissions

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