Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

I have a problem, my program build pyramid as it needs in task but didnt acept my solution.

Your code so far

function pyramid(symbols, rows, side) {
  let row = "";
  let symbolsTotal = rows * 2 - 1
  let spaceLeft = rows;
  let spaceRight = rows;
  if(side == true) {
    for (let i = rows; i > 0; i--) {
      let newRow = "";
      if(i == rows){
        newRow = `${symbols.repeat(symbolsTotal)}`;
        row += newRow;
      }else{
        newRow = `\n${" ".repeat(spaceLeft - i)}${symbols.repeat(symbolsTotal - (spaceLeft - i) - (spaceRight - i))}`;
        row += newRow;
      }
    }
  }else{
    for (let i = 0; i < rows; i++) {
      let newRow = "";
      newRow = `\n${" ".repeat(spaceLeft - i - 1)}${symbols.repeat(symbolsTotal - (spaceLeft - i - 1) - (spaceRight - i - 1))}`;
        row += newRow;
    }
  }
  return row;
}

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

Your browser information:

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

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

You wrote

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

That line logs

   o
  ooo
 ooooo
ooooooo

The instructions asked for

\n   o\n  ooo\n ooooo\nooooooo\n

which is


   o
  ooo
 ooooo
ooooooo

Your output and the requested output are not 100% identical.

I had a similar situation. Because it’s hard to look at our pyramids and figure out why they don’t pass when they look like pyramids/triangles. For debugging, I switched my ‘\n’ with ‘X’, ran the tests and could see where their '\n’s lined up with my X’s. Not sure if that will help you, but it helped me to pass.