Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

Output looks good but code not passing. Thanks for your help!

Your code so far

function pyramid (str, int, bool) {
  let newStr = "";
  if (bool === false) {
    for (let i = 1; i < int * 2; i +=2 )  {
      let space = ((int * 2 - 1) - i) / 2;
      newStr+=`\n${" ".repeat(space)}${str.repeat(i)}`;
    }
  } else if (bool === true) {
    for (let i = int * 2 - 1; i > 0; i -= 2 )  {
      let space = ((int * 2 - 1) - i) / 2;
      newStr+=`\n${" ".repeat(space)}${str.repeat(i)}`;
    }
  }
  return newStr;
}

console.log(pyramid("o", 4, false))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.0

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-pyramid-generator/66f2836c459cfb16ae76f24f.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @besaidaurochs07,

Try testing your code like this to compare actual to expected:

  console.log("Actual:   ", JSON.stringify(pyramid("o", 4, false)));
  console.log("Expected: ", JSON.stringify("\n   o\n  ooo\n ooooo\nooooooo\n"));
  console.log("Actual:   ", JSON.stringify(pyramid("p", 5, true)));
  console.log("Expected: ", JSON.stringify("\nppppppppp\n ppppppp\n  ppppp\n   ppp\n    p\n"));

Happy coding

  1. The pyramid should start and end with a newline character.

Please check this.
You have to add newline character at the end of your answer.