Print Star Pattern in JavaScript

Advertisements

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

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet


Download Projects

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements