Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

Good day. My function appears to be working properly in the console. It produces pyramids and inverts those pyramids based on my boolean value. However, my tests are not passing as it appears to suggest that the function must return one long string of characters broken up by the newline character. Please provide some guidance on where I am going wrong - I may have overcomplicated the answer

Your code so far

function pyramid (string, number, boolean){

let rows = 1;
let space = ' ';
let spaceMultiplier = number;
let stringRepeat = string.repeat(number).split('');
let pyr='';

if (boolean === false){
  
  for (let i = 0; i < stringRepeat.length; i++) {

  pyr += `\n${space.repeat(spaceMultiplier)} ${stringRepeat[i].repeat(rows)}`; 

  rows += 2;
  spaceMultiplier--
  }  

} else if (boolean === true) {

  rows = ((2 * number + 1) - 2);
  spaceMultiplier = 0;
  for (let i = 0; i < stringRepeat.length; i++) {

  pyr+= `\n${space.repeat(spaceMultiplier)} ${stringRepeat[i]. repeat(rows)}`; 

  rows -= 2;
  spaceMultiplier++
} 
} return pyr;

}
  
console.log(pyramid('o', 4, false))


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

use this to see the output of your function: console.log(JSON.stringify(pyramid('o', 4, false)))

in this way you can compare better with the expected output

Thank you, that helped me to solve it.