Build a Pyramid Generator - Build a Pyramid Generator

you can always share the code you have written and describe what you are struggling with to get help

here it is

function pyramid(str, num, bool) {
  let row = ''
  for(let i = 0; i < num; i++) {
    row += '\n'
    if(!bool) {
      for(let k = 0; k < num - i; k++) {
        row += ' ' 
      }

    } else {
      for(let k = num ; k > num - i - 1; k--) {
        row += ' '
      }

    }
    if(!bool) {
      for(let j = 0; j < 2 * i + 1; j++) {
        row += str
      }
    } else {
      for(let j = 2 * num - 2; j > 2 * i - 1; j--) {
        row += str
      }


    }
  }
  return row
}
console.log(JSON.stringify(pyramid('p', 5, true)))  
console.log(pyramid('p', 5, true)) 

can you also describe what you are struggling with?

i did not pass the tests 3 and 4 because of i miss the trailing new lines

a trailing new line is easy to add, but that’s not your only issue

you can change your console.log at the end to this so you can confront your actual output with the expected one:

console.log(JSON.stringify(pyramid('p', 5, true)))  
console.log(JSON.stringify("\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"))
1 Like

oh i see additional spaces when i compare damn my bad

i try to manipulate the code but with random ideas not that i know where specific things should i put here or remove from there

yes, i did it man i did it. thanks very much . i feel so good man that u helped me to do all that

you did all of the work, I just told you how to see better the output

to be honest without you and fCC team how did i know how stupid was i , and how i evolve .

can you please stop with the negative self talk?

you did all the work, celebrate that

yea , iam in a positive feelings now, i mean i wasn’t be able to do that evolving in my level without you . your way to design the challenges is unbelievable