Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

Goodday all! My code refuses to pass the 3rd and 4th steps. Please help

Your code so far

function pyramid(pattern, rows, isDown) {
  let result = "\n";
  for (let i = 1; i <= rows; i++ ) {
    let rowNum = isDown ? (rows - i + 1) : 1;
    let charCount = 2 * rowNum - 1;
    let spaces = " ".repeat(rows - rowNum);
    let row = spaces + pattern.repeat(charCount) + "\n";
    result += row;
  }
  result += "\n";
  return result;
}

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/134.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

do you what is printed to the console? that is not a pyramid

you can also use JSON.stringify in the way below so you can directly compare with the string shown in the tests
console.log(JSON.stringify(pyramid("o", 4, false)));

Thanks for the response, but I don’t know how to progress further. Can you please give me a tip?

have you checked what your function returns against what it should return?

my first tip is to analyze your output and see where it comes from and how it differs from the desired output

It returns the correct output when the boolen is true, pyramid with a vertex facing downwards, but I’m not getting the right ouput when the boolean is false. Please help I’m confused!

rowNum will always be 1 in that case. You need to review your logic

Thanks a lot! I got it now