Tell us what’s happening:
I get error : pyramid should return (“o”, 4, false) should return “\n o\n” etc… but my newlines seems fine no?
Your code so far
function pyramid(char, rows, isTrue)
{
let firstRow;
let charColumns;
let whitespace = " ";
let newLine = "\n";
let bottom;
let changingBottom;
let result = "\n";
if(isTrue === false)
{
for(let r=0; r<rows; r++)
{
if(r===0)
{
result += whitespace.repeat(rows);
result += char;
result += "\n";
}
else if (r>0)
{
result += whitespace.repeat(rows-r);
result += char.repeat(r*2+1);
result += "\n";
}
}
return result;
}
else if (isTrue === true)
{
for(let r=rows; r>0; r--)
{
if(r===0)
{
result += char.repeat(rows*2-1);
result += "\n";
}
else if (r>0)
{
result += whitespace.repeat(rows-r);
result += char.repeat(r*2-1);
result += "\n";
}
}
return result;
}
}
let py = pyramid("o",4,false);
console.log(py);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0
Challenge Information:
Build a Pyramid Generator - Build a Pyramid Generator