Print Number Pattern in JavaScript


Prev Tutorial Next Tutorial

Print Number Pattern in JavaScript

Using JavaScript we can easly 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.

Number Pattern in JavaScript

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

  var a;
var n=prompt("Enter a number for the no. of rows in a pattern");
for(var i=1;i<=n;i++)
 {
  for(var j=1;j<=i;j++)
   {
    document.write("0"+j+" ");
   }
   document.write("<br />");
 }

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

Output

01 
01 02 
01 02 03 
01 02 03 04 
01 02 03 04 05 

Number Pattern in JavaScript

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

 for(i=1; i <= 5; i++)
 {
  for(j=1; j<=i; j++)
 {
   document.write(j);
   if(j == i)
   continue;
   else
   document.write(' ');
  }
   document.write('<br />');
  }
    
</script>
</head>
<body>
</body>
</html>

Output

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

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