loop?... how..

Discussion in 'JavaScript' started by Namuk, Mar 14, 2008.

  1. #1
    i'm very beginner on this programing....

    anyone can help me to do this loop problem...
    how to right code to get the result below

    *
    **
    ***
    ****
    *****

    please help and teach me.....
    thanks....
     
    Namuk, Mar 14, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Mar 14, 2008 IP
  3. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Namuk, Mar 14, 2008 IP
  4. coolcode007

    coolcode007 Well-Known Member

    Messages:
    1,122
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    148
    #4
    as NicoSwd says dont Copy and paste for homework, but here is the code :)


    <script type="text/javascript">
    var i=0;
    var j=0;
    for (i=0;i<=4;i++)
    {
      for (j=0;j<=i;j++){
         document.write("*");
      }
      document.write("<br />");
    }
    </script>
    Code (markup):
     
    coolcode007, Mar 18, 2008 IP
  5. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks a lot..... hehehehe:):):)
     
    Namuk, Mar 18, 2008 IP
  6. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    *........*
    **......**
    ***....***
    ****..****
    **********


    how to doing loop result like this?...
    "." is nothing just a space....
     
    Namuk, Mar 18, 2008 IP
  7. coolcode007

    coolcode007 Well-Known Member

    Messages:
    1,122
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    148
    #7
    hey NamUk i have replied to your email message though DP few days back with the code, not sure you got it

    &nbsp is used to make a space

    
    <script type="text/javascript">
    var i=0;
    var j=0;
    for (i=0;i<=4;i++)
    {
      for (j=0;j<=i;j++){
         document.write("*");
      }
    
      for (j=0;j<=((4-i)*4)-2;j++){
         document.write("&nbsp;");
      }
    
      for (j=0;j<=i;j++){
         document.write("*");
      }
    
      document.write("<br />");
    }
    
    </script>
    
    Code (markup):
     
    coolcode007, Mar 20, 2008 IP
  8. Namuk

    Namuk Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    i got it already.... thanks....
     
    Namuk, Mar 22, 2008 IP