Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

My solution seems to produce the right result, but still fails the test. I could probably make it smarter in relation to test for direction, but I cannot see, why it shouldn’t pass.

Your code so far

function pyramid (character, rows, isFacingDown) {
  let returnString = "";

  if(isFacingDown) {
    for (let i=rows; i>0; i--) {
      returnString += " ".repeat(rows-i) + character.repeat(i*2-1) + "\n";
    }
  } else {
    for (let i=1; i<=rows; i++) {
      returnString += " ".repeat(rows-i) + character.repeat(i*2-1) + "\n";
    }

  }
  console.log(returnString)
  return returnString;
}
pyramid("o", 4, false)
pyramid("p", 5, true)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

Hi there and welcome to our community!

You are missing one tiny addition, which will allow your code to pass the tests.

The pyramid should start and end with a newline character.

Your pyramid ends with a newline character but…

1 Like

Ahh, I see. That should be doable, tanks!

1 Like