Tell us what’s happening:
I have no clue why my code is not passing. When I log the parameters it gives me a pyramid (if the booleanValue is false) or inverted pyramid(if the booleanValue is true) but it still says tests 3 and 4 are failing. I am not sure what else to do.
Your code so far
function pyramid (string, integer, booleanValue) {
let rows = [];
let pyramidShape = "";
function padRows (a, b) {
let newRow = " ".repeat(b - a) + string.repeat(2 * a - 1) + " ".repeat(b - a);
return newRow
}
for (let i = 1; i <= integer ; i += 1) {
if (booleanValue == false) {
rows.push(padRows(i, integer));
} else if (booleanValue == true) {
rows.unshift(padRows(i, integer))
}
}
for (let row of rows) {
pyramidShape = "\n" + pyramidShape + row + "\n";
}
return pyramidShape
}
console.log(pyramid("o", 4, false))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator