Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

it shows the pyramide properly but it says error

Your code so far

function pyramid(str, row, bool){
  
  if(bool===false){
   let space=" ";
  let element=1;
    for(let i=1; i<=row;i++){
      console.log(space.repeat(row-i)+str.repeat(element)+space.repeat(row-i));
      element=element+2;
    }
  }
  else{
    let element=row+(row-1);
    let space=" ";
    for(let i=0; i<row;i++){

      console.log(space.repeat(i)+str.repeat(element-(i*2))+space.repeat(i));
    }
  }

}  

pyramid("p", 5, true);

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

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

For this project, you can add the following to the end of your script to compare what the tests expect to what your code is generating:

console.log("Actual:   ", JSON.stringify(pyramid("o", 4, false)));
console.log("Expected: ", JSON.stringify("\n   o\n  ooo\n ooooo\nooooooo\n"));
console.log("Actual:   ", JSON.stringify(pyramid("p", 5, true)));
console.log("Expected: ", JSON.stringify("\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"));

but does your function return the requested string?