Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

my code is perfect but its asking for an output with new line characters embedded into it

Your code so far


function pyramid(pattern,rows,boolean) {
  let result='';
  if(!boolean)
    {
      for(let i=0;i<rows;i++){ 
      let spaces=' '.repeat(rows-i);
      let char=pattern.repeat(2*i+1)
      let all=spaces+char
      result+=all
        result+='\n'
    }
    }else{
      for(let i=1;i<=rows;i++){ 
        for(let j=0;j<i;j++){
          result +=' '
        }
        for(let k=i;k<=rows;k++){
          result+='%'
        }
        for(let k=i;k<rows;k++){
          result+='%'
        }
  
       
        result+='\n'
      }
    }
  return result
  }
console.log(pyramid('g',4,false))

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) 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

Code definitely isn’t perfect and convincing yourself it is holds back your ability to debug

Why are there two of this loop here?

thankyou for highlighting this I have seen its not helping in any way and this means I have probably made more errors here let me revisit it thankyou soo much