pyramid patters with javascript

How to Print All Pyramid Patters with JavaScript


Here is a quick approach to print pyramid patterns with JavaScript. It’s a simple and easy approach that anyone can easily understand and try on their own. I am taking rows value in every for loop in all the function code blocks.

Increasing Pyramid

increasing pyramid pattern with javascript
increasing pyramid/star pattern with JavaScript
// increasing pyramid

function incPyra(rows){
    for(let i = 0; i <= rows; ++i){
        let pyramid = "* ".repeat(i)
        console.log(pyramid)
    }

}

incPyra(10)

Decreasing Pyramid

decreasing pyramid pattern with javascript
decreasing pyramid/star pattern with JavaScript
// Decreasing pyramid


function decPyra(rows){
    for(let i = rows; i >= 1; --i){
        let pyramid = "* ".repeat(i)
        console.log(pyramid)

    }
}

decPyra(10)

Opposite Side Increasing Pyramid

opposite side increasing pyramid pattern with javascript
opposite side increasing pyramid pattern with JavaScript
// opposite side increasing pyramid pattern with JavaScript

function rpyra(rows){
    for(let i=0; i<=rows; i++){
        let spaces = "  ".repeat(rows-i)
        let stars = "* ".repeat(i)
        console.log(spaces + stars)
    }
}

rpyra(10)

Opposite Side Decreasing Pyramid

opposite side decreasing pyramid pattern with JavaScript
opposite side decreasing pyramid pattern with JavaScript
// opposite side decreasing pyramid pattern with JavaScript

function lpyra(rows){
    for(let i=0; i<=rows; i++){
        let star = '* '.repeat(rows-i)
        let space = "  ".repeat(i)
        console.log(space+star)

    }
}

lpyra(10)

Upside Down Pyramid

upside down pyramid pattern with JavaScript
upside down pyramid pattern with JavaScript
// upsite down pyramid

function usdPyramid(rows){
    for(let i =0; i<=rows; ++i){
        let stars1 = "* ".repeat(rows-i)
        let spaces1 = " ".repeat(i)
        console.log(spaces1 + stars1)
}
}
usdPyramid(10)

Pyramid Pattern

pyramid star pattern with JavaScript
pyramid star pattern with JavaScript
// pyramid

function pyramid1(rows){
    for(let i = 0; i<=rows; i++){
        let spaces = " ".repeat(rows-i)
        let stars = "* ".repeat(i)
        console.log(spaces+stars)
    }
    
}
pyramid1(10)