Build a Pyramid Generator - Build a Pyramid Generator

Tell us what’s happening:

Good day, can I please get assistance, I do not know what is missing here

Your code so far

const stri = "*";
const numRows = 4;
const bool = false;

function pyramid(stri, numRows, bool) {
  let level = "\n";

  if (bool === false) {
  for (let i = 1; i <= numRows; i++) {
   let row = " " + stri.repeat(2*i + 1);
   level += row + "\n";
  }
  } else {
    for (let i = numRows; i >= 1; i--) {
       let row = " " + stri.repeat(2*i + 1);
   level += row + "\n";
    }
  }
  return level;
  }


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


Your browser information:

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

Challenge Information:

Build a Pyramid Generator - Build a Pyramid Generator

As the vertex row should have one character, the following lines should be corrected:

line 10: for (let i = 0; i < numRows; i++) {
line 15: for (let i = numRows-1; i >= 0; i--) {

And as each row should be aligned in center, in line 11 and 16 the spaces must be filled enough:
let row = " ".repeat(numRows-i-1) + stri.repeat(2*i + 1);

Enoy it.

Just swap out the one line of code:

let row = " " + stri.repeat (2i + 1);
with
let row = " ".repeat(numRows - i) + stri.repeat(2
i - 1);

This logic 2*i - 1 starts you with 1 star on row 1 (instead of 3).

Happy coding :slight_smile:

@behappy81327 @venkatasaisandeep

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Got it, thanks for the heads-up! I see how giving hints and asking the right questions helps others learn better than just handing over the full solution. I’ll keep that in mind and focus more on guiding than giving away answers. Appreciate the reminder!