Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

This is the correct solution to the problem though it is not accepted.

Your code so far

function pyramid(pattern,rows,bool){
    let line = ""
    let mainPat = ""
    if(bool===false){
      for(let i=0;i<rows;i++){
      for(let j=rows-i-1;j>=0;j--) line = line + " "
      for(let k=0;k<2*i+1;k++) line = line + pattern
      mainPat=mainPat + line + "\n"
      line=""
    }}
    else{
      for(let i=rows;i>0;i--){
      for(let j=0;j<=rows-i-1;j++) line = line + " "
      for(let k=0;k<2*i-1;k++) line = line + pattern
      mainPat=mainPat + line + "\n"
      line=""
    }
    }
  return mainPat
}
console.log(pyramid("o", 4, false))
console.log(pyramid("p", 5, true))

Your browser information:

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

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-pyramid-generator/66f2836c459cfb16ae76f24f.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @aditighosh668,

Try testing like this to see the issue:

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"));

Happy coding