Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

What is the problem with this code? It creates a pyramid.

Your code so far


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

function pyramid(sine, count, boolean) {

  let str = ''

    if (boolean === true) {

        for (let i = count; i >= 1; i--) {

            for (let j = 1; j <= count - i; j++) {

                str += ' '

            }

            for (let k = 1; k <= 2 * i - 1; k++) {

                str += sine

            }




            str += '\n'

        }

 

    }

    

    for (let i = 1; i <= count; i++) {

        for (let j = 1; j <= count - i; j++) {

            str += ' '

        }

        for (let k = 1; k <= i; k++) {

            str += sine+' '

        }




        str += '\n'

    }





    return str

}




console.log(pyramid("o", 4, false))

make sure your code is returning exactly what is requested

print this to check what your function is returning:

// pyramid("o", 4, false) should return "\n   o\n  ooo\n ooooo\nooooooo\n".
console.log('test 3');
console.log("Actual:   ", JSON.stringify(pyramid("o", 4, false)));
console.log("Expected: ", JSON.stringify("\n   o\n  ooo\n ooooo\nooooooo\n"));

// pyramid("p", 5, true) should return "\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n".
console.log("\n\ntest 4");
console.log("Actual:   ", JSON.stringify(pyramid("p", 5, true)));
console.log("Expected: ",JSON.stringify("\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"));

solution removed by moderator

Congratulations on solving the challenge! You should be proud of your achievement…we are! But we are removing your working solution, so it is not available to others who have not yet done the work to get there. Again, congrats!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.