Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

although the output seems right to me , I keep receiving this message: 3. pyramid(“o”, 4, false) should return “\n o\n ooo\n ooooo\nooooooo\n”.
4. pyramid(“p”, 5, true) should return “\nppppppppp\n ppppppp\n ppppp\n ppp\n p\n”.

Your code so far

function pyramid(pattern,count,bool) {

let rows = [];
let result = "";

function rowBuilder(rowNum) {
return " ".repeat(count-rowNum)+pattern.repeat(2*rowNum-1);
}


for (let i = 1; i <= count; i++) {
  if(bool){  rows.push(rowBuilder(i));}
  else {rows.unshift(rowBuilder(i));}
}

for (const row of rows) {
  result += "\n"+ row;
}
result+="\n";
return result;
}

console.log(pyramid("o", 5, false));


Your browser information:

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

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Have you manually tested what the returned string for those two cases is? When I do, it doesn’t look like the requested result.

1 Like

What does your function return, for comparison?