Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

I couldn’t pass test 3 and 4, what is happening in my code?

Your code so far

function pyramid(str,int,boolean){

let arr1 = [];
let string ="";
for(let i=0;i<int;i++){
  if(boolean===false){

arr1.push(" ".repeat(int-i)+str.repeat(i * 2 + 1)+" ".repeat(int - i));

  }
  else{
    arr1.unshift(" ".repeat(int-i)+str.repeat(i*2+1)+" ".repeat(int-i));
  }
 
}
for(let char of arr1){
string = string +char+"\n"
} 
return string;

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

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator
https://www.freecodecamp.org/learn/full-stack-developer/lab-pyramid-generator/lab-pyramid-generator

Use JSON.stringify() to call your function so you can compare the raw string output with the test.

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

I tried using it, but my console output is " o\n ooo\n ooooo\nooooooo\n".
However, it should be "\n o\n ooo\n ooooo\nooooooo\n". i don’t know where the mistake is in my code.

you are missing the \n at the start, there are a few different places in your code where you can add that missing character

Thank you, it works. :blush: