Tell us what’s happening:
Hopefully this is ok to ask here, I realized after getting this far I should be adding in “\n” instead of having the function console.log the rows separately so I’m going to have to start over regardless, but this function works for the “true” condition except the last line or two (depending on # of rows) reads “undefined” - can anyone help me understand what’s happening in the last iteration or two? I appreciate any input!
Your code so far
function pyramid (unitPattern, numOfRows, isPointingDown) {
let numOfUnits = 0;
let numOfSpaces = -1;
if (isPointingDown === true) {
for (let i = 0; i <= numOfRows; i++) {
numOfSpaces++;
numOfUnits = numOfRows * 2 - 1;
console.log(" ".repeat(numOfSpaces) + unitPattern.repeat(numOfUnits));
numOfRows--;
}
}
}
console.log(pyramid("z", 5, true));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator