Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

I can’t figure out steps 3 and 4, Not understanding how to achieve the desired result, any assistance wii be appreciated.

Your code so far

function pyramid(str, count, bool){ 
  const rows = [];
let results = "";
  if (bool === false){
  for (let i = 1; i <= count; i++){
rows.push(" ".repeat(count - i) + str.repeat((i*2 -1) ) + " ".repeat(count - i))
}} else {
   for (let i = 1; i <= count; i++){
rows.unshift(" ".repeat(count - i) + str.repeat((2 * i) -1 ) + " ".repeat(count - i));
} }
for (const row of rows){
  results  += row+ '\n';
  }
  return results;
}
let test = pyramid("o", 4, false);
console.log(test);
test = pyramid("p",5,true)
console.log(test)
console.log(JSON .stringify(pyramid("o",4,false)))
console.log('\n')
console.log(JSON.stringify(pyramid("p",5,true)))

//console.log('\n``')
//console.log(JSON.stringify("\n   o\n  ooo\n ooooo\nooooooo\n"));
//console.log('\n``')
//console.log(JSON.stringify("\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Take a closer look at the difference between returned string and what’s expected. For example, pyramid("o", 4, false):

"   o   \n  ooo  \n ooooo \nooooooo\n" // returned
"\n   o\n  ooo\n ooooo\nooooooo\n"     // expected
1 Like

Ok so how can i achieve the string result without messing up the actual pyramid(s)

Well, the individual lines that are currently composing the resulting pyramid, need to be modified, to match with what is expected.

I don’t see how i can add a “\n” and not disrupt the pyramid.

  1. You need to initialize the variable “results” like : let results = "\n";
  2. Don’t need to append any spaces at the end (line 6 and 9).
    Be happy