Tell us what’s happening:
I am not sure how to proceed, if I try for example pyramid(“o”, 4, false), I can print out:
row 1: 3 empty spaces, 1 char
row 2: 2 empty spaces, 3 char
row 3: 1 empty space, 5 char
row 4: 0 empty spaces, 7 char
which seems like the test case, what am I missing?
Your code so far
const pyramid = (char, rows, bool) => {
let result = [];
let cRow = 1;
//startMarker
result.push("\n");
if (bool === "false") {
for (let j = cRow; j <= rows; j++) {
//spacing
for (let i = 1; i <= rows - cRow; i++) {
result.push(" ");
}
//char
for (let i = 1; i <= cRow * 2 - 1; i = i + 1) {
result.push(char);
}
//endRow
result.push("\n");
cRow++;
}
}
if (bool === "true") {
for (let j = cRow; j <= rows; j++) {
//spacing
for (let i = cRow; i > 1; i--) {
result.push(" ");
}
//char
for (let i = 2 * rows - cRow; i >= cRow; i -= 1) {
result.push(char);
console.log(`i: ${i}, cRow: ${cRow}`);
}
//endRow
console.log(`result: ${result}`);
result.push("\n");
cRow++;
}
}
//return
return result.join("");
}
let char = "o";
let rows = 4;
let dir = "false";
const result = pyramid(char, rows, dir);
console.log(result);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator