Tell us what’s happening:
Not sure if this is the optimal way to run the code but it should be returning the string that is needed to pass, not sure what the issue is. I do see that for step 4 the string to pass has a “\p” for the second new line command instead of a “\n”, not sure what that is about but that doesn’t explain why step 3 is failing as well. Please help!
Your code so far
const pyramid = (str, rows, boolean) => {
const generator = str;
let times = generator;
let multiply = rows;
let space = ' ';
const array = [];
if (boolean === false) {
for (let i = 0; i < rows; i++){
array.push('\n');
array.push(space.repeat(multiply - 1));
array.push(times);
times += generator + generator;
multiply--;
}
return array.join('').toString();
} else if (boolean === true) {
for (let i = 0; i < rows; i++){
array.unshift(space.repeat(multiply));
array.unshift('\n');
array.unshift(times);
times += generator + generator;
multiply--;
}
}
return array.join('').toString();
}
console.log(pyramid('o', 4, false));
console.log('\n o\n ooo\n ooooo\nooooooo\n')
console.log(pyramid('p', 5, true));
console.log('\nppppppppp\p ppppppp\n ppppp\n ppp\n p\n');
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator