Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

hey im struggling with the build a pyramid Generator in the JavaScript Certification.
I don’t really understand what it wants me to do. as far as i can see the code i have should pass. I also cant find any posts on this, it seems like there is another pyramid generator build in some other certification program involving javascript.
just need a hint at what im doing wrong please and thank you.

Your code so far

function pyramid(character, count, isInverted){
  let returnString = "";
  if(isInverted === false){
      for (let i = 1; i <= count; i++) {
  
        const spaces = " ".repeat(count - i);
        const hashes = character.repeat(2 * i - 1);
  
       returnString += spaces + hashes + spaces + "\n";
  
      }    
  } else if(isInverted === true){
      for (let i = count; i > 0; i--) {
        const spaces = " ".repeat(count - i);
        const hashes = character.repeat(2 * i - 1);
  
        returnString +=  spaces + hashes + spaces + "\n";
      } 
  } else{
        return "not boolean input";
  }
  return returnString;
}


console.log(pyramid("p", 4, true));

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Welcome to the forum @alecgardiner!

Try testing your code like this so you can compare what your code returns to what is 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!

Awesome buddy keep moving