Tell us what’s happening:
My code is returning the expected result but the cant complete it
Your code so far
function pyramid(char, rows, inverted) {
let result = “”;
if (!inverted) {
for(let i = 1; i <= rows; i++){
result += “\n” + " ".repeat(rows - i) + char.repeat(i * 2 - 1);
}
return result;
} else {
for(let i = rows; i >= 1; i–){
result += “\n” + " ".repeat(rows - i) + char.repeat(i * 2 - 1);
}
return result;
}
}
console.log(pyramid(“o”, 4, false));
console.log(pyramid(“p”, 5, true));
function pyramid(char, rows, inverted) {
let result = "";
if (!inverted) {
for(let i = 1; i <= rows; i++){
result += "\n" + " ".repeat(rows - i) + char.repeat(i * 2 - 1);
}
return result;
} else {
for(let i = rows; i >= 1; i--){
result += "\n" + " ".repeat(rows - i) + char.repeat(i * 2 - 1);
}
return result;
}
}
console.log(pyramid("o", 4, false));
console.log(pyramid("p", 5, true));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator