Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

I am not able clear the last 2 tests even though result is correct

Your code so far

function pyramid(character,rowCount,boolean){

const rows = []

function padRow(rowNumber, rowCount) {
  return " ".repeat(rowCount - rowNumber) + character.repeat(2 * rowNumber - 1) + " ".repeat(rowCount - rowNumber);
}

for (let i = 1; i <= rowCount; i++) {
  if (boolean==true) {
    rows.unshift(padRow(i, rowCount));
  } else {
    rows.push(padRow(i, rowCount));
  }
}

let result = ""

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

return result



}
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/137.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Welcome to the forum @mohammedrayaan1

To help you debug, try console logging the pyramid function call.

Happy coding

I have tried console logging the pyramid function and it is correct value. But still the tests does not get cleared.

Then you need to check the spacing.

try logging it using JSON.stringify, like this:

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

this one for example prints "\n o \n ooo \n ooooo \nooooooo"
which is not the same as the desired result "\n o\n ooo\n ooooo\nooooooo\n"

Thanks! I got all the test cleared.