I saw that others have taken a very different approach to this but my code does the job without issue. I don’t understand why it doesn’t pass the test.
I spaces before and after the pyramids are not pretty I admit but I don’t understand their purpose anyway.
Any help is appreciated. Thanks in advance.
Your code so far
function pyramid(char, rows, isFlipped) {
console.log(" ");
// Upright
if (isFlipped === false) {
let size = 1;
for (let i = 0; i < rows; i++) {
console.log(" ".repeat(rows - i) + char.repeat(size));
size+= 2;
}
console.log(" ");
}
// Upside down
else {
let size = rows* 2 - 1;
for (let i = 0; i < rows; i++) {
console.log(" ".repeat(i) + char.repeat(size));
size-= 2;
}
console.log(" ");
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator