SharePoint - Can anyone help out in this - Asked By Mano on 13-Sep-10 08:06 AM

Here i try to print output as like this 
 ******
 *****
 ****
 ***
 **
 *
 here are my codings it will print 5 to 1 on reverse side 
<html>
<head>
<script>
 
    for (x=-5; x <=-1; x=x+1) 
  {
    document.write(x);  
}
</script>
 
</head>
</html>

for this Output is -5 -4 -3 -2 -1 but this is not a format i want to print on here 
how can i reduce numbers on each line and getting Printed as like this

 ****** or -5 -4 -3 -2 -1
 *****       -5 -4 -3 -2
 ****         -5 -4 -3 
 ***           -5 -4 
 **             -5 
 *

Kirtan Patel replied to Mano on 13-Sep-10 08:13 AM
<script language="javascript" type="text/javascript">
   
    var i = 0;
    var j = 0;
    for (i = 1; i <=5; i++) 
    {

      for (j = 5; j >= i; j--) 
      {
        document.write("*");
      }
      document.write("<br/>");
    }
   
  </script>
Henry Taylor replied to Mano on 13-Sep-10 08:20 AM
int y = 1;

while (y <= 5)
{
  for (x=5; x >=y; x++) 
  {  
    switch (x)
    {
      case 5: 
        Console.WriteLine("*****");
        break;
      case 4:
        Console.WriteLine("****");
        break;
      case 3:
        Console.WriteLine("***");
        break;
      case 2:
        Console.WriteLine("**");
        break;
      default:
        Console.WriteLine("*");
        break;
    }
  }
  y++;
}
Super Man replied to Mano on 13-Sep-10 08:31 AM

    var line = 5;

 

    for (var i = 0; i < 5 ; i++) {

 

      for (var j = line - i; j > 0; j--) {

        document.write("*");

      }

      document.write("<br>");

    }

 

    for (var x = 1; x <= line; x++) {

 

      var temp = -5;

      for (var y = 0; y <= line -x; y++) {

        document.write(temp);

        temp = temp + 1;

      }

      document.write("<br>");

    }

 

 

Here first for loop is used for print ‘*’ and second loop is used for numbers

You can see this output:

 

*****
****
***
**
*
-5-4-3-2-1
-5-4-3-2
-5-4-3
-5-4
-5

Top of Form

Bottom of Form

 

Sagar P replied to Mano on 13-Sep-10 09:10 AM
You have to use 2 for loops one is to get total number of lines... and one is for printing *'s like;
And to break the lines you can use <br/> tag like;

var i;
var
 j;
for
 (i = 0; i < 5; i++) 
{
  for
 (j = 5; j > i; j--) 
  {
    document.write(
"*"
);
  }
  document.write(
"<br/>"
);
}