Print Star Pattern in JavaScript


Prev Tutorial Next Tutorial

Print Star Pattern in JavaScript

Using JavaScript we can easily write any programming code, Here we write one of the most popular program Print Star Pattern in JavaScript. To perform this task we need for loop. In JavaScript we use document.write() function to print * on screen.

print star pattern in javascript

Print Triangle of Stars in JavaScript

<html>
<head>
<script type="text/javascript">

  var i, j;
  //outer loop
  for(i=1; i <= 5; i++)
   {
   //inner loop
    for(j=1; j<=i; j++)
   {
     document.write('*');
    }
     document.write('<br/>');
   }

</script>
</head>
<body>
</body>
</html>

Output

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

Print Triangle of Stars in JavaScript

<html>
<head>
<script type="text/javascript">

  var i, j;
  //outer loop
  for(i=5;i>=1;i--)
   {
   //inner loop
    for(j=1;j<=i;j++)
   {
     document.write('*');
    }
     document.write('<br/>');
   }

</script>
</head>
<body>
</body>
</html>

Output

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

Prev Tutorial Next Tutorial

Google Advertisements

Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements