I need my output to look like this:

The best I could achieve was that:

Here is my code:
let pyramidComplete = (rows) => {
let array = [];
let str = '';
for (let i = 1; i <= rows; i++) {
//Add the white space to the left
for (let k = 1; k <= (rows - i); k++) {
str += ' ';
}
//Add the '*' for each row
for (let j = 0; j != (2 * i - 1); j++) {
str += "#".repeat(2 * i - 1);
}
//Add the white space to the right
for (let k = i + 1; k <= rows; k++) {
str += ' ';
}
//Print the pyramid pattern for each row
array.push(str)
str = '';
}
}
pyramidComplete(5);
I thought of assembling a line per loop and then, pushing it into an array but, I can't get the desired result.
function pyramidComplete(rows) { ... }instead. It makes it a lot more clear what you're doing. The=>notation is intended for other situations, like passing that in as an argument.str, create a new one through each iteration of the loop. Thestr = ''part is pointless, justlet str = ''at the start inside the row loop.{}button to mark blocks of code, or indent with four spaces for the same effect. The contents of a screenshot can’t be searched, run as code, or copied and edited to create a solution.