Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

I have no clue why my code is not passing. When I log the parameters it gives me a pyramid (if the booleanValue is false) or inverted pyramid(if the booleanValue is true) but it still says tests 3 and 4 are failing. I am not sure what else to do.

Your code so far

function pyramid (string, integer, booleanValue) {
  let rows = [];
  let pyramidShape = "";

  function padRows (a, b) {
    let newRow = " ".repeat(b - a) + string.repeat(2 * a - 1) + " ".repeat(b - a);
    return newRow
  }

  for (let i = 1; i <= integer ; i += 1) {
    if (booleanValue == false) {
    rows.push(padRows(i, integer));
    } else if (booleanValue == true) {
    rows.unshift(padRows(i, integer))
    }
  }

  for (let row of rows) {
    pyramidShape = "\n" + pyramidShape + row + "\n";
  }

  return pyramidShape
}

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

try writing console.log(JSON.stringify(pyramid("o", 4, false)))

I would guess there is something wrong with your new line characters

I tried and it returns the code
" o \n ooo \n ooooo \nooooooo\n"
can you please help me fix this?

the passing line should be
“\n o\n ooo\n ooooo\nooooooo\n”

I figured it out! Here is the passing code.

function pyramid (string, integer, booleanValue) {
 SOLUTION REMOVED BY MODERATOR
  for (let row of rows) {
    pyramidShape = pyramidShape + row;
  }
  return pyramidShape
}

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

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

Well done for solving the challenge. We are trying to cut down the number of spoilers on the side so I have removed the solution from your code.

Oops sorry about that :frowning:

1 Like