Tell us what’s happening:
I have achieved the effects of these four, but I didn’t pass
Your code so far
function pyramid(o,n,b){
//pyramid pyramid("o", 4, false) 应该返回 "\n o\n ooo\n ooooo\nooooooo\n"
//pyramid pyramid("o", 4, true) 应该返回 "\n o\n ooo\n ooooo\nooooooo\n ooooo\n ooo\n o\n"
let result = "";
if(b){
for(let i = n; i >= 1; i--){
result += " ".repeat(n - i) + o.repeat(2 * i - 1) + "\n";
}
}else{
for(let i = 1; i <= n; i++){
result += " ".repeat(n - i) + o.repeat(2 * i - 1) + "\n";
}
}
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/135.0.0.0 Safari/537.36
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator