Tell us what’s happening:
I am getting the right pyramid shape but the JSON string is not what the tast is looking for. It looks like it needs to be joined with .join() but im having troubles where in my function am I able to implement that.
Please could someone provide me with an idea of where this might go? or if its something else im missing? thank you
Your code so far
function pyramid(pattern, rows, inverted) {
let result = "";
if (!inverted) {
for (let i = 1; i <= rows; i++) {
const row = " ".repeat(rows - i) + pattern.repeat(2 * i - 1) + " ".repeat(rows - i);
result += "\n" + row;
}
}
else {
for (let i = rows; i >= 1; i--) {
const row = " ".repeat(rows - i) + pattern.repeat(2 * i - 1) + " ".repeat(rows - i);
result += "\n" + row;
}
}
return result
}
console.log("Actual: ", JSON.stringify(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/142.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator