Tell us what’s happening:
Am i going crazy? It’s doing exactly what’s it’s supposed to do…
Your code so far
function pyramid (string, rows, trueorFalse) {
let result = "";
if (trueorFalse === false) {
for(let i = 0; i < rows; i++) {
let char = string.repeat(2 * i + 1);
let space = " ".repeat(rows - i - 1);
result += space + char + "\n";
}
} else {
for(let j = rows - 1; j >= 0; j--) {
let char = string.repeat(2 * j + 1);
let space = " ".repeat(rows - j - 1);
result += space + char + "\n";
}
}
return result;
}
console.log(pyramid("p", 5, true));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:147.0) Gecko/20100101 Firefox/147.0
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator
