Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

The test says I am not completing points 3 and 4 but in the console I am returning the string they want me to return. I am completely lost and I am not seeing what the error is. Help

Your code so far

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

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

if you write your console.logs like this:

console.log(JSON.stringify(pyramid("o", 4, false)));
console.log(JSON.stringify(pyramid("p", 5, true)));

you can compare with the two strings shown in the tests

or like this you have actual and expected on top of each other:

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

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.