Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

My output is working exactly as it should be. And it follows all the test it shows. Yet it somehow show’s it’s failing test 3 and 4. But I have compared their output and mine, those are like exact same.
Please help me!

Your code so far

const pyramid = (str, num, bool) => {
  let ans = "\\n";
  if(bool === false) {
    for(let i=0; i<num; i++) {
      for(let j=0; j<num-i-1; j++) {
        ans += " ";
      }
      for(let k=num-i-1; k<num; k++) {
        ans += str;
      }
      for(let j=0; j<i; j++) {
        ans += str;
      }
      ans += "\\n";
    }
  }
  else if(bool === true) {
    for(let i=0; i<num; i++) {
      for(let j=0; j<i; j++) {
        ans += " ";
      }
      for(let k=i; k<num; k++) {
        ans += str;
      }
      for(let j=0; j<num-i-1; j++) {
        ans += str;
      }
      ans += "\\n";
    }
  }
  return ans;
}

// let anss = pyramid("p", 5, true)
// console.log(anss)
// console.log("\\n   o\\n  ooo\\n ooooo\\nooooooo\\n")
// console.log("\\nppppppppp\\n ppppppp\\n  ppppp\\n   ppp\\n    p\\n")

Your browser information:

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

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

You can test like this to compare actual to expected:

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