Build a Pyramid Generator - Build a Pyramid Generator

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

try this: console.log(JSON.stringify(py)); so it is easier to confront with the requested output written in the tests

I figured out what was wrong… the counter in the for loop of the upwards facing pyramid was counting from 0-11, and I used the “r” (which only counted up to 11) to calculate the pyramid.. and in the other for loop it counted from 12 to 1, which means I could use the number 12 to calculate in the downwards facing pyramid, (Which means it was closer to the left of the screen than the upwards facing pyramid) … freecodecamp threw an error because of that.. because I planted the upwards facing pyramid one whitespace more to the right than the downward facing pyramid..

The solution was simply to decrement the rows length by 1 in the upward facing pyramid…

Thanks for checking in on me