Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

My code actually returns the required output, but I can’t past the test 3 and 4, please what is wrong with my code

Your code so far

[Spoiler]function pyramid(char, num, vertex) {
  let space = " ";
  let pyramid = "\n";
  let counter = 1;
  let y = 2;
  if(vertex == false){
    for(let i = 0; i < num; i++){
  let spaces = space.repeat(num -i);
  let characters = char.repeat(counter);
pyramid = pyramid.concat(spaces, characters, '\n');
  counter += y;
  }
  return pyramid
  }else if(vertex == true){
    for(let i = 0; i < num; i++){
      let spaces = space.repeat(num - i)
      let charac = char.repeat(counter)
      pyramid = pyramid.concat(spaces, charac, "\n")
      counter += y
    }
    return pyramid.split(" ").reverse().join(" ")
  }
}
console.log(pyramid("+", 4, false));[/spoiler]

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Mobile Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

I took the function call from the failing test and wrote it like this:

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

so it prints "\n o\n ooo\n ooooo\n ooooooo\n", now we can confront with the requested output:

actual:   "\n    o\n   ooo\n  ooooo\n ooooooo\n"
expected: "\n   o\n  ooo\n ooooo\nooooooo\n"

do you see some differences?

Thanks for showing me this, it made the problem more visible to tackle