Tell us what’s happening:
My code is not passing and I’m unclear as to why. I thought it was because of the way i added “\n”, but it does not appear to make a difference at the beginning or end of where I’m generating my pyramid variable within the loop. Is it something to do with how I’m using the counter? Thanks in advance!
Your code so far
const pyramid = (character, rows, inverted) => {
let pyramid = '';
if (inverted) {
console.log("I'm true!")
for (let i = rows; i >= 1; i--) {
const chars = character.repeat(2 * i-1);
const spaces = ' '.repeat(rows - i)
// console.log('chars:', chars, "spaces:", spaces)
pyramid += '\n' + spaces + chars + spaces
}
} else {
console.log("I'm false!")
for (let i = 1; i <= rows; i++) {
const chars = character.repeat(2 * i -1);
const spaces = ' '.repeat(rows - i);
// console.log("spaces:", spaces)
// console.log("numChars", numChars)
pyramid += '\n' + spaces + chars + spaces
}
}
return pyramid;
};
console.log(pyramid('p', 5, true))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator
https://www.freecodecamp.org/learn/full-stack-developer/lab-pyramid-generator/lab-pyramid-generator