JavaScript Program to Print Pyramid Star Pattern Last Updated : 27 Sep, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will demonstrate how to create pyramid star patterns in JavaScript. The Possible Pyramid Star Patterns are:Upper pyramidInverted pyramidLeft inverted pyramidRight inverted pyramidApproachThere will be two different approaches based on alignments i.e. horizontal and vertical. Horizontally Inverted PyramidThis type includes the upper pyramid and the inverted pyramid.To achieve this we will use a javascript for loop to iterate N time In that loop, print spaces repeat N-1 times before and after the start.As the number of start changes by 2 in every line repeat the stars 2*i -1 times to get the required structure.Vertically Inverted PyramidVertically inverted pyramids include the Rigth inverted and Left inverted pyramidsTo achieve this we will use Javascript for loop 2 time i.e. from 1 to N and back to 1.In that loop, print spaces repeat N-i times before and after the start.As the number of start changes by 1 in every line repeat the stars i times to get the required structure.Example 1: Upper pyramid JavaScript let n = 5; for (let i = 1; i <= n; i++) { let str = "* "; let space = ' '; console.log(space.repeat((n - i)) + str.repeat(i * 2 - 1)); } Output * * * * * * * * * * * * * * * * * * * * * * * * * Example 2: Inverted pyramid JavaScript let n = 5; for (let i = n; i >= 1; i--) { let str = "* "; let space = ' '; console.log(space.repeat((n - i)) + str.repeat(i * 2 - 1)); } Output* * * * * * * * * * * * * * * * * * * * * * * * * Example 3: Left inverted pyramid JavaScript let n = 5; for (let i = 1; i <= n; i++) { let str = "* "; let space = ' '; console.log(space.repeat((n - i)) + str.repeat(i)); } for (let i = n - 1; i >= 1; i--) { let str = "* "; let space = ' '; console.log(space.repeat(n - i) + str.repeat(i)); } Output * * * * * * * * * * * * * * * * * * * * * * * * * Example 4: Right inverted pyramid JavaScript let n = 5; for (let i = 1; i <= n; i++) { let str = "* "; console.log(str.repeat(i)); } for (let i = n - 1; i >= 1; i--) { let str = "* "; console.log(str.repeat(i)); } Output* * * * * * * * * * * * * * * * * * * * * * * * * Comment More infoAdvertise with us Next Article JavaScript Program to Print Pyramid Star Pattern J jatinsharmatu54 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions JavaScript-Program Similar Reads JavaScript Program to Print Square Star Pattern In this article, we are going to discuss how we can make a square star pattern. we have to print "*" in the console in such a way that it turns or looks like a solid square. we can use loops in different manners for this pattern. Example: Input: 4Output: * * * * * * * * * * * * * * * * Input: 3Outpu 5 min read JavaScript Program to Print the Pattern G This program aims to print the pattern 'G' using asterisks (*) in the console output. The pattern 'G' consists of several horizontal and vertical lines arranged to form the uppercase letter 'G'. It requires careful positioning of asterisks to represent the shape accurately. Below are the methods to 3 min read JavaScript Program to Print Floydâs Pattern Triangle Pyramid Floyd's Triangle is a right-angled triangular array of natural numbers, used primarily in computer science education. It is named after Robert Floyd. Each row of the triangle corresponds to the sequence of consecutive natural numbers. In this article, we will explore different approaches to implemen 2 min read JavaScript Program to Print Triangle Star Pattern This article will show you how to make a triangle star pattern using JavaScript. We'll use a for loop to iterate through the number of rows, and in each iteration we will use a for loop for the n number of iterations, and in each loop we will print the "*" with the repeat method to increase or decre 3 min read JavaScript Program to Print Diamond Shape Star Pattern This article will demonstrate how to create the diamond start pattern in JavaScript. Possible Diamond Start Patterns:Solid Diamond Start PatternHollow Diamond Star PatternInverted Hollow Diamond PatternApproach to Create Diamond Star Pattern:The approach to creating a diamond star pattern will use 2 3 min read JavaScript Program for Hollow Pyramid Star Pattern In this article, we will demonstrate how to create Hollow Pyramid Star Patterns in JavaScript. Possible Hollow Pyramid Star Patterns areUpper pyramidInverted pyramidLeft inverted pyramidRight inverted pyramidApproachThere will be two different approaches based on alignments i.e. horizontal and verti 3 min read JavaScript Program to Print Double Sided Stair-Case Pattern This JavaScript program is designed to print a double-sided staircase pattern. A double-sided staircase consists of steps where each step has numbers incrementing from 1 to the current row number on the left side, and then decrementing from the current row number - 1 down to 1 on the right side. The 3 min read JavaScript Program to Print Pyramid Pattern by using Numbers A pyramid pattern using numbers is a sequence of numbers arranged in a triangular shape, with each row displaying incrementing or decrementing numbers, creating a visually structured pattern. Example: 1 1 2 3 1 2 3 4 5 1 2 3 4 5 6 71 2 3 4 5 6 7 8 9ApproachWe initialize a variable n with the value 5 5 min read JavaScript Program to Print Reverse Floyd Pattern Triangle Pyramid Printing a reverse Floyd pattern triangle pyramid involves outputting a series of numbers in descending order, forming a triangular shape with each row containing one less number than the previous row. The numbers are arranged in such a way that they form a right-angled triangle, reminiscent of Floy 2 min read JavaScript Program to Print Number Pattern The idea of pattern-based programs is to understand the concept of nesting for loops and how and where to place the alphabet/numbers/stars to make the desired pattern. These are the following approaches to printing different types of number patterns:Table of Content Using nested loops Using array ma 2 min read Like