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 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 Inverted Hollow Star Pyramid In this article, we will write a Program to Print an Inverted Hollow Star pyramid. Possible Inverted Hollow Star Pyramid Patterns are Inverted pyramidLeft inverted pyramidRight inverted pyramidThere will be two different approaches based on alignments i.e. horizontal and vertical:Table of Content Ho 3 min read JavaScript Program to Print Inverted Pyramid In JavaScript, the Inverted Pyramid is the geometric pattern of "*" that is arranged in the format upside-down. This can be printed using various approaches like Looping, Recursion, and built-in methods. Table of Content Using Nested for LoopUsing RecursionUsing Array and Join methodsUsing Nested fo 3 min read JavaScript Program to Print 180 Rotation of Simple Pyramid A program to print 180 rotations of a simple pyramid involves iterating through a loop 180 times, each time printing the pyramid with a different orientation. This is achieved by adjusting the number of spaces and asterisks printed in each row to create the desired pyramid shape. There are several w 2 min read Like