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