How to print star pattern program in JavaScript?

Today, We want to share with you pyramid program in javascript.In this post we will show you pyramid js, hear for write a program to print number pattern in javascript we will give you demo and example for implement.In this post, we will learn about number pyramid program in php with an example.

How to display pyramid using JavaScript?

Example 1:

function generatePyramid() {
    var totalNumberofRows = 5;
    var output = '';
    for (var i = 1; i <= totalNumberofRows; i++) {
        for (var j = 1; j <= i; j++) {
            output += j + '  ';
        }
        console.log(output);
        output = '';
    }
}

generatePyramid();

Print pyramid pattern of numbers and stars

Example 2:

var totalRw=5;
for(var i=1;i<=totalRw;i++)
{
	for(var j=1;j<=i;j++)
	{
		document.write(" * ");
	}
	document.write("
"); }
//Output:
*
* *
* * *
* * * *
* * * * *

Displaying pyramid using for loop:

Example 3:

var totalRw = 5;
for(var i=1; i<=totalRw; i++)
{
	for(var k=1; k<=( totalRw-i ); k++)
	{
		document.write(" ");
	}

	for(var j=1; j<=i; j++)
	{
		document.write("* ");
	}
	document.write("
"); }
Output:
    *
   * *
  * * *
 * * * *
* * * * *

I hope you get an idea about javascript patterns program.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment